Tutorial :C# Get URL path from local directory



Question:

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.


Solution:1

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


Solution:2

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


Solution:3

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(@":\",@"$\");  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »