flynn Posted March 16, 2006 Posted March 16, 2006 Can anyone point me to the C# equivalent of the C++ CHttpFile object? Basically the C++ code just queries the size of a BINARY file that will be downloaded, sets up a progress bar and then does the download. Here is what I am converting: CHttpFile *pHttpFile; CFile file; pHttpFile = (CHttpFile*)NetSession.OpenURL(m_cstrHTTPServer + "/TestFile.exe", 1, INTERNET_FLAG_TRANSFER_BINARY | INTERNET_FLAG_RELOAD); // get the length of the file dwTemp = 0; if (pHttpFile->QueryInfo(HTTP_QUERY_CONTENT_LENGTH, cstrTemp)) dwTemp = atol(cstrTemp); if (file.Open(m_cstrUpdatePath, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary)) { // copy 1KB at a time from server to local file UINT nRead = pHttpFile->Read(szBuff, 1023); while (nRead > 0) { file.Write(szBuff, nRead); // make sure messages are still processed during this loop MSG msg; if(::PeekMessage(&msg,m_hWnd,0,0,TRUE)) { ::TranslateMessage(&msg); ::DispatchMessage(&msg); } if (m_bStop) break; m_ctrlProgress.StepIt(); // Add in bytes read ulTotalRead += nRead; cstrTemp.Format("Downloaded %d KB out of %d KB (%d%%).", ulTotalRead / 1024, dwTemp / 1024, (int)(((double)(ulTotalRead) / 1024.00) / ((double)(dwTemp) / 1024.00) * 100.00)); m_stStatus.SetWindowText(cstrTemp); nRead = pHttpFile->Read(szBuff, 1023); } file.Close(); } I could use this: System.Net.WebClient client = new System.Net.WebClient(); client.DownloadFile(UpdateServer + "/TestFile.exe","C:\\Data\\TestFile.bin"); which works, but doesn't allow me to update a progress bar like the C++ code. Does anyone have a C# example I could look at? tia, flynn Quote
Administrators PlausiblyDamp Posted March 17, 2006 Administrators Posted March 17, 2006 http://www.xtremedotnettalk.com/showthread.php?t=81155 might be what you want. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
flynn Posted March 17, 2006 Author Posted March 17, 2006 http://www.xtremedotnettalk.com/showthread.php?t=81155 might be what you want. Excellent, Thank You PlausiblyDamp, and Thank You dynamic_sysop for the example. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.