Very tricky problem here. I want to now create an intranet web page that allows a user to upload these videos and set the relative path in the sql table column.

Posted on 2005-05-10
Last Modified: 2010-04-07
I have an intranet site that displays flash video presentation titles in a datagrid. For each flash video I store the file path in a sql table column. Thats fine.

Now suppose within my website there is a folder called flashmovies which contains all the movies. So the relative path to any flash movie would be


I want to now create an intranet web page that allows a user to upload these videos and set the relative path in the sql table column.

There are two challenges in this problem as I see it

1/ I need to upload flash movie files into a directory on the server

2/I need to create a way for the user to easily browse to the uploaded file and set a site relative path to link to the file.

Step 1 I think I will manage, however is there any object within .net that will allow a client user to set the relative file path. ie can I give them a browse button or something to browse to the file.

Your help would be greatly appreciated.


Paul G
Question by:pgilfeather
    LVL 2

    Expert Comment

    Paul - Not sure I understand the question. Are all the swf files uploaded to the same directory on the webserver? If so, what o you mean by 'setting a site relative path' - can you elaborate?
    LVL 26

    Expert Comment

    1 u said u can manage ..

    >>2/I need to create a way for the user to easily browse to the uploaded file and set a site relative path to link to the file.
    why would the user need to browse to the path or set a relative path, its upto u how u code it .. right?

    lets say a user upload a file A.swf and b.swf .. just show them as links in a web page (ShowUploadedFiles.aspx) .. so if ur directory structure is
       flashmovies - contains all the flash movies
       WebPages - this directory contains all the web pages, It also contains the page ((ShowUploadedFiles.aspx) which displays the list of files he has uploaded . this page would have a hyperlinks
     <a href=../flashmovies/A.swf>A</A>
    <a href=../flashmovies/B.swf>B</A>
    u could use a datagrid .. add a hyperlinkcolumn for the filenames, get the list of filenames the current user uploaded from ur table into a dataset .. bind the dataset to the datagrid ..

    Author Comment


    I have not been very clear, and since posting this question my main focus and priorities have changed slightly. Please accept my apologies for this.

    What I am trying to do is create a server file management system where a user can upload files (via the web page) and then if necessary delete ones that are no longer required. I have found code online that does the upload but it only lets you upload to a hardcoded folder and you cannot delete the files once they are there.

    Here take a look at the code yourself

    Public Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim root As String = "C:\temp"
            Dim thisPage As String = Request.Path

            currentDir = Request.Params("dir")
            If currentDir Is Nothing Then
                currentDir = root
            End If
            If Not currentDir.StartsWith(root) Then
                currentDir = root
            End If

            Dim sb As New StringBuilder(4096)

            If Not currentDir.Equals(root) Then
                ' not at the root
                Dim currentDirParent As String
                Dim lastIndex As Integer = _
                If lastIndex <> -1 Then
                    currentDirParent = currentDir.Substring(0, lastIndex)
                    currentDirParent = currentDir
                End If
                sb.Append("<a href=").Append(thisPage)
                sb.Append("><img width=30 border=0 src=images/Up.gif></a><br>")
            End If


            sb.Append("<br><img border=0 src=images/OpenFolder.gif>&nbsp;")
            sb.Append("<font face=verdana>")

            sb.Append("<tr bgcolor=#D8D8D8>")
            sb.Append("<td width=200><font face=verdana size=3>Name</font></td>")
            sb.Append("<td><font face=verdana size=3>Type</font></td>")
            sb.Append("<td><font face=verdana size=3>Size</font></td>")
            sb.Append("<td><font face=verdana size=3>Modified</font></td>")

            Dim dirs() As String
                dirs = Directory.GetDirectories(currentDir)

                Dim d As String
                For Each d In dirs
                    Dim dirName As String = Path.GetFileName(d)
                    sb.Append("<td><img src=images/Folder.gif>&nbsp;")
                    sb.Append("<a href=").Append(thisPage)
                    sb.Append("<td><font face=verdana size=2>folder</font></td>")
                    sb.Append("<td><font face=verdana size=2>")
                    sb.Append(Directory.GetLastWriteTime(currentDir & _
                      directorySeparatorChar.ToString() & dirName).ToString())


            Catch ex As Exception
            End Try

                Dim dirInfo As New DirectoryInfo(currentDir)
                Dim files() As FileInfo
                files = dirInfo.GetFiles()

                Dim f As FileInfo
                For Each f In files
                    Dim filename As String = f.Name
                    sb.Append("<td><img src=images/File.gif>&nbsp;")
                    sb.Append("<a href=PaulsDownloads.aspx?file=")
                    sb.Append("<td><font face=verdana size=2>file</font></td>")
                    sb.Append("<td><font face=verdana size=2>")
                    sb.Append("<td><font face=verdana size=2>")
                    sb.Append(File.GetLastWriteTime(currentDir & _
                      directorySeparatorChar.ToString() & f.Name).ToString())
            Catch ex As Exception
            End Try

            dirContent.Text = sb.ToString()
        End Sub

        Sub DoUpload()

            If Not (uploadedFile.PostedFile Is Nothing) Then
                    Dim postedFile = uploadedFile.PostedFile
                    Dim filename As String = Path.GetFileName(postedFile.FileName)
                    Dim contentType As String = postedFile.ContentType
                    Dim contentLength As Integer = postedFile.ContentLength
                    postedFile.SaveAs(currentDir & _
                      directorySeparatorChar.ToString() & filename)
                Catch ex As Exception
                    message.Text = "Failed uploading file"
                End Try
            End If
        End Sub

    and for the download page

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim root As String = "C:\temp\"
            Dim filepath As String = Request.Params("file")
            Dim filename As String = Path.GetFileName(filepath)
            If Not filepath Is Nothing Then
                If File.Exists(filepath) And filepath.StartsWith(root) Then

                    Response.ContentType = "application/octet-stream"
                    Response.AddHeader("Content-Disposition", _
                      "attachment; filename=""" & filename & """")
                End If
            End If
        End Sub

    So my conclusion to my problem is that what I am trying to do is potentially very complicated to code.

    Please tell me Im wrong.

    Hope this makes more sense.


    Paul G
    LVL 2

    Assisted Solution

    Not sure what the above code does, but if I understand you, what you want to do is pretty easy.

    You can use the HtmlInputFile html control to allow the user to select a local file to upload. On postback, use the System.IO.File class to save the posted file data to a website directory (you will probably need to resolve the physical path of the directory using e.g. Server.MapPath())

    To delete files, display a list of files from the sql table with a delete option for each. Again, use the  System.IO.File class to perform the delete on postback
    LVL 26

    Accepted Solution

    i do not y u feel delete of file is a tough job .. anyway here is a link to the complete code of a similar requirement .. it has everything that you wish to code for .. upload, delete, view etc .. also option to created directories .. etc .. remember if ur site is configured for anonynous access, then directory permission (full control) will have to be given to the ASPNET user ...

    File Upload Manager

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
    I have developed many web applications with asp & and to add and use a dropdownlist was always a very simple task, but with the new, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now