File names are changed during e-mail send.

Last post 07-09-2009 5:11 AM by mudassarkhan. 6 replies.

Sort Posts:

  • File names are changed during e-mail send.

    07-08-2009, 6:38 AM
    • Member
      10 point Member
    • Skag55
    • Member since 01-16-2009, 6:25 PM
    • Posts 124

    Hi all,

    I have set up a function to send an email with attachments. It is supposed to send a couple of htmls, a text file, and a couple of .xls files.

    When I receive it, everything works fine, but the .xls files are named ATT00001.xls ATT00002.xls etc...The rest naming convention is correct. I don't understand how some file names are correct and some other are not when they all go through the same function...

    Any thoughts on this? Any help would be much appreciated.

     

    Thank you in advance 

  • Re: File names are changed during e-mail send.

    07-08-2009, 8:02 AM
    • All-Star
      59,913 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 10:28 AM
    • Mumbai, India
    • Posts 10,551
    • TrustedFriends-MVPs

     You can give names to attachment

    http://weblogs.sqlteam.com/jeffs/archive/2003/11/14/513.aspx

    Refer here 

  • Re: File names are changed during e-mail send.

    07-09-2009, 3:01 AM
    • Member
      10 point Member
    • Skag55
    • Member since 01-16-2009, 6:25 PM
    • Posts 124

    Thank you for your answer mudassarkhan .

    I need to maintain the original names that the user has uploaded.

    Thanks 

  • Re: File names are changed during e-mail send.

    07-09-2009, 3:23 AM
    • All-Star
      59,913 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 10:28 AM
    • Mumbai, India
    • Posts 10,551
    • TrustedFriends-MVPs

     

    Give the original names to Attachment.Name property since if you don't give name to Attachment it will rename it

  • Re: File names are changed during e-mail send.

    07-09-2009, 4:46 AM
    • Member
      10 point Member
    • Skag55
    • Member since 01-16-2009, 6:25 PM
    • Posts 124

    Hi and thank you for your answers.

    I am using this:

    string a = ViewState["Readersfilename"].ToString();

    message.Attachments.Add(new Attachment(MapPath(a)));

     

    After your suggestion I changed that to

    string a = ViewState["Readersfilename"].ToString();

    message.Attachments.Add(new Attachment(MapPath(a), a));

    However it accepts a IO.Stream as the first argument, and I don't want to go there. I just want to input the file to be attached and maintain the original name...

  • Re: File names are changed during e-mail send.

    07-09-2009, 5:07 AM
    • Member
      10 point Member
    • Skag55
    • Member since 01-16-2009, 6:25 PM
    • Posts 124

    Actually here's my complete code for that. I suspect it has to do with the persisting of the controls or something?

    for (int i = 9; i < 12; i++)
    
    
    { 
       fu =   (FileUpload)Page.FindControl("FileUpload" + i.ToString());
                if (fu.HasFile)
                {
                    ViewState["Readerspath"] = fu.PostedFile.FileName.ToString();
                    ViewState["Readersfilename"] = fu.FileName.ToString();
                    fu.SaveAs(MapPath(@fu.FileName.ToString()));
                    ViewState["readers" + re.ToString()] = fu.FileName.ToString();
                    string a = ViewState["Readersfilename"].ToString();
                    message.Attachments.Add(new Attachment(MapPath(a)));
                    re++;
    
                   }
    
    } 
    
    


     

  • Re: File names are changed during e-mail send.

    07-09-2009, 5:11 AM
    Answer
    • All-Star
      59,913 point All-Star
    • mudassarkhan
    • Member since 02-28-2008, 10:28 AM
    • Mumbai, India
    • Posts 10,551
    • TrustedFriends-MVPs

     Do this way

     

     

     

    Attachment attachFile = new Attachment(txtAttachment.PostedFile.InputStream, strFileName);

    Refer my article

    http://www.aspsnippets.com/post/2009/02/15/Attaching-files-from-Stream-using-FileUpload-Control.aspx

    There is no option other than passing origna filename to attachment

     

     

Page 1 of 1 (7 items)