Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0uploading files in secure foldersuploading files in secure folders
Previous
 
Next
New Post
1/21/2009 8:41 PM
 

Hello

I'm programming a module which needs to upload files to a secure folder. Which class/method must I use to do it?

Users need also downloads this files uploaded from that secure folder.

In a secured folder, secured files has the word "resources" after de file extension. How must i make the link to the file?

Thanks.

 
New Post
1/22/2009 12:09 PM
 

I'v found the solution by myself looking de source code of DNN proyects.

The next piece of code uploads a file using secure system file (type 1)

 

Private Function SubirArchivo() As Boolean

            If FileUploadAdjuntos.HasFile Then
                If ((Not FileUploadAdjuntos.PostedFile Is Nothing) And (FileUploadAdjuntos.PostedFile.ContentLength > 0)) Then
                    Try
                        'Se obtienen el nombre del archivo y el archivo físico
                        Dim fileName As String = System.IO.Path.GetFileName(FileUploadAdjuntos.PostedFile.FileName)
                        Dim NewFileName As String = Me.Session.SessionID & "_" & fileName
                        Dim filePath As String = System.IO.Path.Combine(PortalSettings.HomeDirectoryMapPath & _CarpetaAdjuntos, NewFileName)
                        'Si ya existe se borra
                        Dim YaExiste As Boolean = False
                        For Each Archivo As ListItem In LbAdjuntos.Items
                            If fileName = Archivo.Text Then
                                YaExiste = True
                                FileSystemUtils.DeleteFile(Archivo.Value)
                                Archivo.Value = filePath
                            End If
                        Next

                        Dim postedFile As HttpPostedFile = FileUploadAdjuntos.PostedFile
                        Dim strMessage As String = FileSystemUtils.UploadFile((PortalSettings.HomeDirectoryMapPath & _CarpetaAdjuntos & "\").Replace("/", "\"), postedFile, NewFileName, False)

                        If strMessage <> "" Then
                            'LbAdjuntos.Visible = False
                            'BtnAdjuntosAgregar.Visible = False
                            'BtnAdjuntosQuitar.Visible = False
                            'FileUploadAdjuntos.Visible = False
                            'Me.PanelAdjuntos.Controls.Add(New LiteralControl("<p class='Normal'>" & strMessage & "</p>"))
                            Exit Function
                        End If

                        'se agrega al listado
                        If Not YaExiste Then LbAdjuntos.Items.Add(New ListItem(fileName, filePath))
                        'se oculta o no el botón quitar
                        BtnAdjuntosQuitar.Visible = (LbAdjuntos.Items.Count > 0)

                        Return True
                    Catch ex As Exception
                        PanelAdjuntos.Visible = False
                        DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, ex.Message, Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
                    End Try
                Else
                    DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, "seleccione un archivo", Skins.Controls.ModuleMessage.ModuleMessageType.RedError)
                End If
            Else
                Return False
            End If
            'HttpContext.Current.Trace.Write("Uploads(): txtFileName.Text=" & txtFileName.Text)
        End Function

 

I use this other piece to generate the links. Only users which has permisions can download the files:

 

...


            While Archivos.Read()
                Dim objFileController As New DotNetNuke.Services.FileSystem.FileController
                Dim FileName As String = Archivos("Archivo").ToString.Replace("/", "\").ToLower.Replace(HomeDirecTory.ToLower.Replace("/", "\"), "").Replace(_CarpetaAdjuntos.ToLower.Replace("/", "\"), "").Replace("\", "")
                Dim objFolder As DotNetNuke.Services.FileSystem.FolderInfo = FileSystemUtils.GetFolder(PortalId, _CarpetaAdjuntos)
                Dim objFile As DotNetNuke.Services.FileSystem.FileInfo = objFileController.GetFile(FileName, PortalId, objFolder.FolderID)
                Dim FileLink As String = DotNetNuke.Common.Globals.LinkClick("fileid=" & objFile.FileId.ToString, Me.PortalSettings.ActiveTab.TabID, -1)
                EnlacesArchivos &= "<a href='" & FileLink & "' target='_blank' Class='Normal' width='100%'><img src='" & Icono(Archivos("Nombre")) & "' border='0' align='absmiddle'/>&nbsp;" & Archivos("Nombre") & "</a>&nbsp;&nbsp;"
            End While


...

 

LinkClick function retunrs each url to FileLink an the result is something like this: http://......./LinkClick.aspx?fileticket=INguERx0CBc%3d&tabid=140

 

Enjoy it!!!!!

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0uploading files in secure foldersuploading files in secure folders


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out