locked
Help with FileUpoadControl RRS feed

  • Question

  • User599355300 posted

    Hi,

    Im trying to build a file upload form which has this as part of the code :

    try
    {
    string filename = Path.GetFileName(FileUploadControl.FileName);
    FileUploadControl.SaveAs(Server.MapPath(@"~/Data/") + filename);
    StatusLabel.Text = "Upload status: File uploaded!";
    }

    is it possible to change the path to save the file to my D:\Data?  At the moment its trying to upload to  'C:\inetpub\wwwroot\Upload2\'

    Many Thanks,

    Fiorano

    Friday, August 23, 2019 9:12 AM

Answers

  • User-821857111 posted

    FileUploadControl.SaveAs(@"D:\Data\" + filename);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 23, 2019 10:39 AM

All replies

  • User-821857111 posted

    FileUploadControl.SaveAs(@"D:\Data\" + filename);

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, August 23, 2019 10:39 AM
  • User665608656 posted

    Hi fiorano,

    is it possible to change the path to save the file to my D:\Data?  At the moment its trying to upload to  'C:\inetpub\wwwroot\Upload2\'

    Yes, it is possible.

    Server.MapPath(@"~/Data/") returns an absolute path based on a folder relative to your application. 

    If you want to store to D:\Data, you can use this code:

     string fileName = Path.Combine(@"D:\Data", filename);
     //save the file to our local path
     FileUploadControl.SaveAs(fileName);

    You can refer to this link : https://stackoverflow.com/a/10479970

    Best Regards,

    YongQing.

    Monday, August 26, 2019 7:24 AM
  • User599355300 posted

    Thanks!  Worked perfectly

    Tuesday, August 27, 2019 7:48 AM