C# 从本地目录获取 URL 路径

发布于 2024-07-23 12:25:20 字数 336 浏览 6 评论 0原文

这是我的程序: 我正在将图像(Stream、FileInfo 或任何您喜欢的内容)上传到此虚拟目录中的服务器:“C:\_Resources\Assets”

但是,我希望服务器返回该图像的 URL 路径以将其显示在一个标签,也就是说“http://localhost/Trunk/Assets/image.jpeg

事实上,我正在尝试做与 Server.MapPath 方法相反的事情。

请问我怎样才能得到它?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蒲公英的约定 2024-07-30 12:25:20

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

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

世界如花海般美丽 2024-07-30 12:25:20

为什么不直接创建一个字符串并将“C:_Resources”替换为“/Trunk”?
可能并不理想,但它应该可以帮助您前进。

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

南冥有猫 2024-07-30 12:25:20
string file = "\\\\" + someServer + "\\" + someFile;
file = file.Replace(":\\","$\\");

而且,如果您不想使用那些转义字符......

string file = @"\\" + someServer + @"\" + someFile;
file = file.Replace(@":\",@"$\");
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(@":\",@"$\");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文