File upload name

Last post 01-11-2012, 11:43 AM by websitepro. 9 replies.
Sort Posts: Previous Next
  •  06-28-2011, 9:54 AM 68202

    File upload name

    When I upload a file, say Test123.doc, it uploads to the directory as
     
    persisted.[someguid].Test123.doc.resx
     
    Is there any way to have the control upload the file as just Test123.doc?
     
    If not, how can I determine what the name of the file is going to be so I can rename it? The guid seems random. 
  •  06-28-2011, 10:55 AM 68205 in reply to 68202

    Re: File upload name

    Hi djnotepad,
     
    You can refer to the following code, the highlighted line will move the temporary files to destination folder and save as your actual file name:
     
    <%@ Page Language="C#" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <script runat="server">
     void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }
        void Uploader_FileUploaded(object sender, UploaderEventArgs args)
        {
            Uploader uploader = (Uploader)sender;
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");

            //Copys the uploaded file to a new location.
            args.MoveTo("c:\\temp\\"+args.FileName);
            //You can also open the uploaded file's data stream.
            //System.IO.Stream data = args.OpenStream();
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Simple Upload with Progress</title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div class="content">
                <h2>
                    Simple Upload with Progress</h2>
                <p>
                    A basic sample demonstrating the use of the Upload control.</p>
                <CuteWebUI:Uploader runat="server" ID="Uploader1" InsertText="Upload File (Max 10M)"
                    OnFileUploaded="Uploader_FileUploaded">
                    <ValidateOption MaxSizeKB="10240" />
                </CuteWebUI:Uploader>
                <br />
                <br />
                <div>
                    Server Trace:
                    <br />
                    <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                </div>
            </div>
        </form>
    </body>
    </html>

    Thanks for asking
  •  06-28-2011, 2:14 PM 68215 in reply to 68205

    Re: File upload name

    I'm having the same problem but it's saving the file as stated in the first email.  I was using args.CopyTo and changed to args.MoveTo .  It sometimes works OK and sometimes doesn't.  This is on a web server so I can't have a hardcoded path.  I've been using:

    Dim txtFolderName As String = "TempUploader\" & args.FileName

    args.CopyTo(txtFolderName)
     
    Hope you can help.
     
    Carolyn Obenberger
  •  06-28-2011, 2:48 PM 68217 in reply to 68215

    Re: File upload name

    -
  •  06-28-2011, 2:48 PM 68218 in reply to 68215

    Re: File upload name

    Hi CarolynObenberger,
     
    When doesn't work, is there error message thrown?
     
    Thanks for asking
  •  06-28-2011, 3:15 PM 68221 in reply to 68218

    Re: File upload name

    No, just saves with the long crazy name.
  •  06-28-2011, 8:18 PM 68230 in reply to 68221

    Re: File upload name

    Hi CarolynObenberger,
     
    You can rename the filename by your own rule when saving
     For example 
      
    1. Dim txtFolderName As String = "TempUploader\" & DateTime.Now().ToString("yyyyMMddHHmmss") & Path.GetExtension(args.FileName)  
    2.         args.MoveTo(txtFolderName)  
     
    Regards,
    Jeff 
  •  01-10-2012, 2:30 PM 72596 in reply to 68202

    Re: File upload name

    I would like to know this as well please. Can someone elaborate on this please.
    Is there a way to have it save the first time as a normal image? withou having to call MoveTo?
  •  01-10-2012, 10:51 PM 72609 in reply to 72596

    Re: File upload name

    Websitepro,
     
    When all sites are uploaded, they will get a temp file name  with .resx extension. Those temp files will be removed by ajax uploader automatically.
     
    You need to call MoveTo to specify the file uploading target path.

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  01-11-2012, 11:43 AM 72634 in reply to 72609

    Re: File upload name

    Thanks. I did not know they automatically were deleted. I was trying to resolve another issue I was having by doing this, but knowing they are deleted automatically will help resolve this  issue. thanks.
View as RSS news feed in XML