Visual Studio Development Bookmark and Share   
 index > Visual C# Express Edition > how to download only a part of the file using c#
 

how to download only a part of the file using c#

hi

ive been tryin to download a file asparts using mutiple threadsinC#...

how can i request the thread to download only a range of bytes ... say starting the download directly from 100000th byte of a file whose location and size are know...

it is found that "WebRequest.AddRange();" can be used for the above stated purpose

can any one help with a sample code that ll serve my purpose..

thank you

cheers

bye

Sakthi Kumaran  Friday, March 30, 2007 6:52 AM

Hi,

Yes, WebRequest.AddRange() can do it.

For example (C# code):

string GetWebPageContent(string url)
{
string result = string.Empty;
HttpWebRequest request;
const int bytesToGet = 1000;
request = WebRequest.Create(url) as HttpWebRequest;

//get first 1000 bytes
request.AddRange(0, bytesToGet - 1);

// the following code isalternative, you may implementthe function afteryour needs
using (WebResponse response = request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
return result;
}

For more information,see: http://ihorwill.blogspot.com/2006/09/http-partial-get.html

Thanks

-----------------------------------------------------------------------------------------------------------------------

These links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet

Figo Fei  Tuesday, April 03, 2007 2:10 AM

Hi,

Yes, WebRequest.AddRange() can do it.

For example (C# code):

string GetWebPageContent(string url)
{
string result = string.Empty;
HttpWebRequest request;
const int bytesToGet = 1000;
request = WebRequest.Create(url) as HttpWebRequest;

//get first 1000 bytes
request.AddRange(0, bytesToGet - 1);

// the following code isalternative, you may implementthe function afteryour needs
using (WebResponse response = request.GetResponse())
{
using (StreamReader sr = new StreamReader(response.GetResponseStream()))
{
result = sr.ReadToEnd();
}
}
return result;
}

For more information,see: http://ihorwill.blogspot.com/2006/09/http-partial-get.html

Thanks

-----------------------------------------------------------------------------------------------------------------------

These links reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you.

Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there.

There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet

Figo Fei  Tuesday, April 03, 2007 2:10 AM

how can i make that data to be written to a file .. any help is appreciated.

sp3tsnaz  Thursday, October 15, 2009 4:21 AM

You can use google to search for other answers

Custom Search

More Threads

• private DateTime? marriageDate;
• ComboBox get SelectedValue ItemArray[2]
• DGV CellFormatting
• forgot something!
• Low Bandwidth MSDN.
• How to check if data is in dataGridView Control
• Windows service application in Visual C# Express
• C# how to read text from a notepad.exe when the notepad is closed
• help me with 2 problems!
• Cannot connect to SQL2005 Express