C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 300,510 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,923 people online right now. Registration is fast and FREE... Join Now!




Problem with download Code

 

Problem with download Code

mager1794

3 Jul, 2009 - 09:39 PM
Post #1

D.I.C Head
**

Joined: 23 Mar, 2009
Posts: 73

I can't seem to get my program to download the full files

such as the file i want is 142 kb it only gets 49
can anyone help

CODE

Client.DownloadFile(new Uri(m_settings.UrlToDownloadFrom + file), file);


thats what i have

m_settings.UrlToDownloadFrom is the url
file = is the string for the file

User is offlineProfile CardPM
+Quote Post


RudiVisser

RE: Problem With Download Code

4 Jul, 2009 - 10:09 PM
Post #2

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,873



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
That could be an issue with the server not returning the correct Content-Length header, I don't think WebClient adheres to the problem where it's not set.

You could try it manually:
CODE
HttpWebRequest hwr = (HttpWebRequest)WebRequest.Create(m_settings.UrlToDownloadFrom + file);
WebResponse wr = hwr.GetResponse();
// You can check the filesize it returns with: wr.ContentLength
Stream dlStream = wr.GetResponseStream();
FileStream fStream = new FileStream(file, FileMode.Create);
byte[] dlRead = new byte[1024 * 4];
int dlCount = dlStream.Read(dlRead, 0, dlRead.Length);
while(dlCount > 0)
{
    fStream.Write(dlRead, 0, dlCount);
    dlCount = dlStream.Read(dlRead, 0, dlRead.Length);
}
dlStream.Close();
fStream.Close();
wr.Close();

User is online!Profile CardPM
+Quote Post

mager1794

RE: Problem With Download Code

5 Jul, 2009 - 01:16 PM
Post #3

D.I.C Head
**

Joined: 23 Mar, 2009
Posts: 73

Got it some reason

making it check if the file exist or not and deleting it if it did fixed it some how
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 05:11AM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month