Click here to Skip to main content
12,946,164 members (55,959 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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 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?
Sanjaci 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;
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
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,205
Maciej Los 2,453
Jochen Arndt 1,935
ppolymorphe 1,795

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