Click here to Skip to main content
11,637,415 members (62,777 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0

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
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?
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
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

       private void butsync_Click(object sender, EventArgs e)

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 304
1 OriginalGriff 295
2 stibee 288
3 270
4 himanshu agarwal 184
0 OriginalGriff 9,031
1 Sergey Alexandrovich Kryukov 8,643
2 Mika Wendelius 6,959
3 F-ES Sitecore 2,388
4 Suvendu Shekhar Giri 2,320

Advertise | Privacy | Mobile
Web02 | 2.8.150728.1 | Last Updated 4 Apr 2014
Copyright © CodeProject, 1999-2015
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