KymZen
KymZen

Reputation:

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.

Upvotes: 3

Views: 7068

Answers (3)

AutomationNation
AutomationNation

Reputation: 547

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

Upvotes: 0

Aditya
Aditya

Reputation: 25

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

Upvotes: 2

TWith2Sugars
TWith2Sugars

Reputation: 3434

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

Upvotes: 1

Related Questions