Click here to Skip to main content
15,887,434 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi,

Can anyone help or assist me for this,

I want download a file(may be a PDF) in a windows C# application. The file is available in a folder where the application's EXE is available. how to do that without the use of FTP or webclient etc...

Thanks in Advance
Posted

If this is a windows application, and the file is already in the application exe directory, they you don't need to download it - the EXE can read the file, so it can either use File.Copy[^] to copy it to a new location, or read it as bytes, and write it back to it's new folder.

Why would you think of this as a download?
 
Share this answer
 
Comments
CyborgForever 13-Mar-12 5:02am    
I want to display a file on click to view file. The user can have the folder with exe in any drive like c or D...How can I specify the file path.
OriginalGriff 13-Mar-12 5:19am    
Do you mean how do you get the user to specify the path to the file?
CyborgForever 20-Mar-12 7:37am    
Yes exactly.
OriginalGriff 20-Mar-12 7:45am    
Open a file browser dialog:

SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = "PDF Files (*.PDF) | *.PDF| All Files|*.*";
if (sfd.ShowDialog() == DialogResult.OK)
{
// Copy your file to sfd.FileName.
string s = sfd.FileName;
}
C#
private void DownloadFile()
       {

           wc.DownloadProgressChanged += WcOnDownloadProgressChanged;
           wc.DownloadFileCompleted += WcOnDownloadFileCompleted;
           string downloadUrl = ConfigurationSettings.AppSettings["fileDownloadPath"] ;


           wc.DownloadFileAsync(new Uri(downloadUrl), @"C:\\fileName" );
           handle.WaitOne(); // wait for the async event to complete

       }

       private void WcOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
       {
           if (!e.Cancelled && e.Error == null)
           {
               //async download completed successfully

           }
           handle.Set(); // in both the case let the void main() know that async event had finished so that i can quit
       }

       private void WcOnDownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
       {
           // handle the progres in case of async
           //e.ProgressPercentage

       }
       private void butsync_Click(object sender, EventArgs e)
       {
           DownloadFile();
}
 
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