ASP.NET C# - Save FileStream on server

后端 未结 3 1727
自闭症患者
自闭症患者 2021-01-26 10:46

I got beginners question.

How to save a file stream to a file on server?!

I got this:

var source = Request.QueryString[\"src\"];
WebClient webcli         


        
相关标签:
3条回答
  • 2021-01-26 11:30

    You can use code to get the website's directory and form your own file path.

    See this question for how to get the website's directory.

    How to get website's physical path on local IIS server? (from a desktop app)

    0 讨论(0)
  • 2021-01-26 11:43

    You need to map your server's path :

    If memory serves me right, you can use something like :

    HttpContext.Current.Server.MapPath("~/MyPathToSomething");
    

    Note that the path string must start with the tilde character.

    Regards

    0 讨论(0)
  • 2021-01-26 11:50

    Use Server.MapPath() (also a using block for closing the file would help):

    using(FileStream os = new FileStream(Server.MapPath("/output/asdasdasd.ico"), FileMode.Create))
    {
       var ic = MakeIcon(iconbitmap, 16, false); /// function returns an icon
       ic.Save(os);
    }
    
    0 讨论(0)
提交回复
热议问题