How to get real filename from a url in C#? -
i want filename url download manager application. know using uri.absolutepath
or path.getfilename
these methods don't give results urls.
for example, in link realname winrar 5.40 final tr.zip, path.getfilename
gives zjesdhoqm?key=035db62f2375981abf05c615955812a72d5f2701 strange name.
there no redirection link. contains file directly. want ask, there exact way correct filename in c#?
update: have figured out link expires. sorry that. couldn't other url explain problem.
if want test problem, can renew url page.
i have found solution myself.
public static string getfilename(string url) { httpwebrequest req = requestsender.sendrequest(url); httpwebresponse resp = req.getresponse() httpwebresponse; string header_contentdisposition = resp.headers["content-disposition"]; string escaped_filename = new contentdisposition(header_contentdisposition).filename; return uri.unescapedatastring(escaped_filename); }
so finally, filename correct. tried help.
Comments
Post a Comment