c# - How to get the type of data from a URL -
c# - How to get the type of data from a URL -
after implementing basic version of simple downloader, have spent few hours googling know how type of url .mp3,.mp4 etc.for sites such daily motion etc who's url don't have appended @ end.this because downloader works these types link without specific types makes download kb's file having nil play.
here code determine content-type decide *.extension downloading:
webclient mywebclient = new webclient(); string datastring = mywebclient.downloadstring("http://www.dailymotion.com/video/x1viyeu_pakistani-actress-meera-reema-saima-dance-on-faisal-ahmed-music-album-launch_news"); namevaluecollection headers = mywebclient.responseheaders; foreach (string key in headers.allkeys) { console.writeline("header:{0},value:{1}", key, headers[key]); }
it returned me list of outputs on console among line was:
header:content-type,value:text/html;charset=utf-8
now want hear how help me counter issue described.
suggestions please
here code downloader
private void downloadbtn_click(object sender, eventargs e) { webclient mywebclient = new webclient(); //declarations string objects string downloadurl, path; //raw url taken user downloadurl = this.downloadurl.text; path = this.savepath.text; uri tmp = new uri(downloadurl); string endpathfilename = tmp.segments.last(); path = path + @"\" + endpathfilename; //downloads file using async method mywebclient.downloadfileasync(tmp, path); downloadbtn.text = "download started"; downloadbtn.enabled = false; mywebclient.downloadprogresschanged += new downloadprogresschangedeventhandler(client_downloadprogresschanged); mywebclient.downloadfilecompleted += new asynccompletedeventhandler(client_downloadfilecompleted); }
usually there content-type
header can give hint of file type expect.
many times server provide info regarding filename - see this so on how done on (php) server side.
c#
Comments
Post a Comment