File Uploading using Server.MapPath() and FileUpload.SaveAs()

前端 未结 4 1985
梦如初夏
梦如初夏 2021-02-09 09:51

I have a website admin section which I\'m busy working on, which has 4 FileUpload controls for specific purposes. I need to know that , when I use the Server.MapPath()

相关标签:
4条回答
  • 2021-02-09 10:17

    yes, that can be used after saving file and when you try retrieve that file...

    Server.MapPath("~/Images/Logos/" + uploadedFileName);
    
    0 讨论(0)
  • 2021-02-09 10:24

    It's one line of code:

     FileUpload1.PostedFile.SaveAs(Server.MapPath(" ")+"\\YourImageDirectoryOnServer\\"+FileUpload1.FileName);
    
    0 讨论(0)
  • 2021-02-09 10:29
    • If you intend to save the files in a directory on your web server , then the Server.MapPath() will be the suitable solution.

      string dirPath = System.Web.HttpContext.Current.Server.MapPath("~") + "/Images/Logos/"+ fileBreak[0] + counter.ToString() + "." + fileBreak[1];

      Look Here

    • if you intend to save your files out the web server then

      Use a full path, like "c:\uploads" and be sure that the web process has permission to write to that folder,I suggest you store the path itself in the web.config file in this case.

    0 讨论(0)
  • 2021-02-09 10:33

    Yes it should still work as Server.MapPath uses the relative values and returns the complete physical path.

    0 讨论(0)
提交回复
热议问题