Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
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 12-Mar-12 21:13pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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?
  Permalink  
Comments
Sanjaci at 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 at 13-Mar-12 5:19am
   
Do you mean how do you get the user to specify the path to the file?
Sanjaci at 20-Mar-12 7:37am
   
Yes exactly.
OriginalGriff at 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;
}
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
}
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,725
1 OriginalGriff 6,696
2 CPallini 5,315
3 George Jonsson 3,589
4 Gihan Liyanage 2,650


Advertise | Privacy | Mobile
Web02 | 2.8.140922.1 | Last Updated 4 Apr 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100