Help

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Help

Guest-12

dear brettle,

i only know a little about vb.net. im just trying to make a simple upload page so that i can upload stuff to my computer when im at school, but i have no clue where to start with your script. i like it alot especially because it's free. i can actually see the file in the temp dir appear and grow in size but when the upload is complete the file disappears... can you show me how to make it so that when it's complete it gets renamed back to it's original name and stays in the temp dir? thanks alot for your work on this script and allowing us to use it for free!

regards,

david

Reply | Threaded
Open this post in threaded view
|

Re: Help

Dean Brettle
Administrator
I have very little experience with VB.NET, but my understanding is that you need to add / modify your Page_PreRender() method so it looks something like:

      Private Sub Page_PreRender(sender As Object, e As EventArgs) Handles MyBase.Page_PreRender
         If Me.IsPostBack Then
            If Not (inputFile.TmpFile Is Nothing) Then
                inputFile.TmpFile.MoveTo(inputFile.FileName)
            End If
         End If
      End Sub 'Page_PreRender

That will move the file to whatever the current directory is (if the server has the necessary permissions).  To move the file to a different location, change the parameter passed to MoveTo() so that it specifies the full path.  If you really want to put it in the temp directory, I believe you'd use:

inputFile.TmpFile.MoveTo(Path.Combine(Path.GetTempPath(), inputFile.FileName))

Hope that helps,

--Dean
PS. Translations courtesy http://authors.aspalliance.com/aldotnet/examples/translate.aspx
Reply | Threaded
Open this post in threaded view
|

Re: Help

Guest-12
thanks for your quick response, actually i dont really mind if it's in vb or c#. i'm still a little lost, could you give me a bit of code so that i code stick it in your demo and get it to actually keep the file when it's done? then i could just modify the html & tinker with the code to get it to work. thanks alot! =)

regards,
david
Reply | Threaded
Open this post in threaded view
|

Re: Help

Dean Brettle
Administrator
Add the following line to Demo.aspx.cs in the Page_PreRender() method:

inputFile.TmpFile.MoveTo(Path.Combine(Path.GetTempPath(), inputFile.FileName));

That should result in the file being put in the temp directory under the name that was used on the client machine.  NOTE: if you are uploading from IE, inputFile.FileName will actually be a full path (ie "C:\path\to\file.ext").  So, you might want to do something more like:

fileName = inputFile.FileName;
if (fileName.IndexOf(@":\") != -1 || fileName.StartsWith("//"))
{
    int lastBackslashPos = fileName.LastIndexOf(@"\");
    if (lastBackslashPos != -1)
    {
       fileName = fileName.Substring(lastBackslashPos + 1);
    }
}
inputFile.TmpFile.MoveTo(Path.Combine(Path.GetTempPath(), fileName));

--Dean