简体   繁体   中英

C# Get URL path from local directory

Here is my program: I'm uploading an image(Stream, FileInfo or whatever you like) to a server at this virtual directory: "C:\\_Resources\\Assets"

But then, I want the server to return the URL path of that image to display it in an tag, that is to say " http://localhost/Trunk/Assets/image.jpeg "

In fact, I'm trying to do the opposite of the Server.MapPath Method.

How do I get that please?

Thanks.

url =“\\\\”+ Environment.MachineName + Path.GetFullPath(document.FileName).ToString()。Split(':')[1];

Why not just create a string and replace the "C:_Resources" with "/Trunk" ? Might not be ideal but it should get you going.

string file = "\\\\" + someServer + "\\" + someFile;
file = file.Replace(":\\","$\\");

And, if you don't feel like using those sill escape characters...

string file = @"\\" + someServer + @"\" + someFile;
file = file.Replace(@":\",@"$\");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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