栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > .Net

c# uri 取文件名

.Net 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

c# uri 取文件名

How can I get a file name if the address ends with something like this.

/download/file/36fdd4aebda3819d329640ce75755657bc0c0d4c6811432b3bb6aac321dc78d/ ?

This is the simplified code example,

void geckoWebBrowser1_Navigating(object sender, GeckoNavigatingEventArgs e)

{

if (e.Uri.AbsolutePath.Contains("/file/"))

{

MyUrl = e.Uri.ToString();

// and here I tried different codes construstors, methods but I can not get the filename

}

if (e.Uri.Segments[e.Uri.Segments.Length - 1].EndsWith(".exe"))

{

// if the address ended with the FileName this code works well

Uri u = new Uri(e.Uri.ToString());

string filename = Path.GetFileName(ut.LocalPath);

MessageBox.Show(fileName);

}

}

解决方案

It doesn't have a "file name", unless there's a Content-Disposition header, including a filename-parm. It might resemble:

Content-Disposition: attachment; filename=FileA.abc

In that case, the file name would be FileA.abc.

I've not really worked with the WebClient class, however, and I don't see any easy way to access the headers. You'd have to switch to using HttpWebRequest, and do more work yourself.

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/908925.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号