简体   繁体   English

使用C#在虚拟目录上上传文件?

[英]Upload file on virtual directory using c#?

I want to store audio file on virtual directory I have created using C#. 我想将音频文件存储在使用C#创建的虚拟目录中。 I have setup the virtual directory in IIS7 . 我已经在IIS7中设置了虚拟目录。 \\webserver\\recordtest\\1234.ogg is my path on other machine, now I'm storing directly on this path, but I want to use virtual directory instead of this which I have configured in IIS7 and which belongs to same path. \\ webserver \\ recordtest \\ 1234.ogg是我在另一台机器上的路径,现在我直接存储在该路径上,但是我想使用虚拟目录而不是我在IIS7中配置的虚拟目录,它属于同一路径。

using (FileStream fs = new FileStream(@"\\webserver\recordtest\1234.ogg", FileMode.Append))
{
    fs.Write(bytes, 0, bytes.Length);
}

You have to use the Server.MapPath method to resolve the virtual path to the physical path. 您必须使用Server.MapPath方法将虚拟路径解析为物理路径。

using (FileStream fs = new FileStream(Server.MapPath(@"YourVirtualPath"), FileMode.Append))
{
    fs.Write(bytes, 0, bytes.Length);
}

Where YourVirtualPath is the path to the directory you created on IIS (which points to \\\\webserver\\recordtest\\1234.ogg ). 其中YourVirtualPath是您在IIS上创建的目录的路径(指向\\\\webserver\\recordtest\\1234.ogg )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM