Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Alright so I've been playing around with various blocks of code from around the web and I can't seem to get this to work :(

Note I am not that skilled in programming in C# however I do have quite a bit of knowledge.

Okay so basically what I want to do is download a file from rapidshare using my premium account, and it seems to work fine, untill you try to open the file.

After the download, I attempt opening the file and it always gives me this error:

"The NTVDM CPU has encountered an illegal instruction.
CS:05a IP:fffe OP:ff ff 00 00 00 Choose 'Close' to terminate the application."

Now the title of this popup us "16 bit MS-DOS Subsystem", so I'm assuming the file i've download is being regarded as being 16 bit. It isn't though, it's actually a small program that I made earlier this year.

Here is the chunk of code that I'm using to perform the download:
private void downloadFile()
{
    string url
        =                @"http://rapidshare.com/files/412151386/GE_Item_Finder.exe";

    // Create an instance of WebClient
    WebClient client = new WebClient();
    client.Credentials = new NetworkCredential("username", "password");//I fill in these with my own details



    // Hookup DownloadFileCompleted Event
    client.DownloadFileCompleted +=
        new AsyncCompletedEventHandler(client_DownloadFileCompleted);

    // Start the download and copy the file to c:\temp
    Uri fileUri = new Uri(url);
    client.DownloadFile(fileUri, "C:\\Temp\\" + Path.GetFileName(url));
    //System.Threading.Thread.Sleep(100);
}

void client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
    MessageBox.Show("File downloaded");
}



Well that's it, if anybody could please tell me what I'm doing wrong, and perhaps offer a solution to my problem, it would be of great use.

Thanks in advance :)
- Raz
Posted
Comments
Richard MacCutchan 14-Nov-10 12:45pm    
Either your file was built for a different platform or it has been corrupted somehow. Try downloading in your browser to see if that works.
Raztor0 14-Nov-10 12:48pm    
I did download from within my browser, and the file does work. And no I am currently using that exact version of the file on a daily basis, I built it for windows (I don't know any other programming languages anyway :P).

1 solution

I had to do something similar to this, can't gaurantee the approach is the same but this should work as well. The alternative to the 2nd part (I'm unsure here) is to use another HttpWebRequest instead of webclient. but when I surf to the url you gave it prompts me to "login" or use the "free version" - i.e. you can't just surf the url and get the file. It's important to note that when doing these requests from .NET the internal browser does not share your session information with IE or any other browser you may be using.


C#
CookieContainer cookies = new CookieContainer();
string username = "UserName";
string password = "Password";
string outputStr = string.Empty;
string mainUrl = @"http://www.rapidshare.com"; // Will need to determine the exact login url
string downloadUrl = @"http://rapidshare.com/files/412151386/GE_Item_Finder.exe";
HttpWebRequest webreq = HttpWebRequest.Create(mainUrl) as HttpWebRequest;
webreq.Method = "POST";
webreq.ContentType = "application/x-www-form-urlencoded";
webreq.CookieContainer = cookies;
string postData = "usrlogin=" + username + "&usrpassword=" + password; // Will need to view source on the login page to find the values to post
StreamWriter reqWriter = new StreamWriter(webreq.GetRequestStream());
reqWriter.Write(postData);
reqWriter.Close();
// I would normally get the response to confirm I've logged in
HttpWebResponse webResp = webreq.GetResponse() as HttpWebResponse;
StreamReader respRDR = new StreamReader(webResp.GetResponseStream());
outputStr = respRDR.ReadToEnd();
respRDR.Close();
webResp.Close();
respRDR.Close();
using (WebClient client = new WebClient())
{
    client.Headers.Add(cookies.GetCookieHeader(new Uri(mainUrl));
    client.DownloadFile(downloadUrl, @"c:\GE_Item_Finder.exe");
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900