[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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
5
Medium Priority
?
218 Views
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

/flashmovies/flashmovie1.swf

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.

Regards

Paul G
0
Comment
Question by:pgilfeather
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:SThorogood
ID: 13967768
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?
0
 
LVL 26

Expert Comment

by:Rejojohny
ID: 13967821
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
Root
   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 ..
0
 

Author Comment

by:pgilfeather
ID: 13969930
Sorry,

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 = _
              currentDir.LastIndexOf(directorySeparatorChar)
            If lastIndex <> -1 Then
                currentDirParent = currentDir.Substring(0, lastIndex)
            Else
                currentDirParent = currentDir
            End If
            sb.Append("<a href=").Append(thisPage)
            sb.Append("?dir=").Append(Server.UrlEncode(currentDirParent))
            sb.Append("><img width=30 border=0 src=images/Up.gif></a><br>")
        End If

        DoUpload()

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

        sb.Append("<table>")
        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>")
        sb.Append("</tr>")


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

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


            Next

        Catch ex As Exception
        End Try


        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("<tr>")
                sb.Append("<td><img src=images/File.gif>&nbsp;")
                sb.Append("<a href=PaulsDownloads.aspx?file=")
                sb.Append(Server.UrlEncode(currentDir))
                sb.Append(directorySeparatorChar)
                sb.Append(Server.UrlEncode(filename))
                sb.Append(">").Append(filename).Append("</a>")
                sb.Append("</td>")
                sb.Append("<td><font face=verdana size=2>file</font></td>")
                sb.Append("<td><font face=verdana size=2>")
                sb.Append(f.Length.ToString())
                sb.Append("</font></td>")
                sb.Append("<td><font face=verdana size=2>")
                sb.Append(File.GetLastWriteTime(currentDir & _
                  directorySeparatorChar.ToString() & f.Name).ToString())
                sb.Append("</font></td>")
                sb.Append("</tr>")
            Next
        Catch ex As Exception
        End Try

        sb.Append("</table>")
        dirContent.Text = sb.ToString()
    End Sub

    Sub DoUpload()

        If Not (uploadedFile.PostedFile Is Nothing) Then
            Try
                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.Clear()
                Response.ContentType = "application/octet-stream"
                Response.AddHeader("Content-Disposition", _
                  "attachment; filename=""" & filename & """")
                Response.Flush()
                Response.WriteFile(filepath)
            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.

Regards

Paul G
0
 
LVL 2

Assisted Solution

by:SThorogood
SThorogood earned 600 total points
ID: 13970159
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
0
 
LVL 26

Accepted Solution

by:
Rejojohny earned 1400 total points
ID: 13975264
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
http://www.codeproject.com/aspnet/FileUploadManager.asp
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month19 days, 1 hour left to enroll

834 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