How to Transfer files from IIS 7 Web server to Local computer

Does anyone know how to program C# so that I can get files in a folder on the web server and transfer then programmatically to the user's computer? I am able to use web.downloadfile to get them on the server but from there I have hit a dead end?

Bill Fennell
fenbi01Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Paul MacDonaldDirector, Information SystemsCommented:
I'm not sure I understand the question.  You want to push files from a web server to a client?  Can you not arrange the client to click a link to begin the download process?
0
Christopher KileCommented:
Perhaps you misstated your question.  WebClient.DownloadFile(String,String) downloads a file from the server to the client, not the client to the server; as long as each file you want to download has a valid URL associated with it, you should be able to download it using this method.

Can you tell us a little more about what you're doing, what you've tried, and what exactly happened (with any messages you received during the process)?  Thanks in advance.
0
fenbi01Author Commented:
Here is my code. I have masked the ip address to the server as we do not yet have a URL for it.

I am creating a dataset of file names. They are already extracted from the database into a folder which has a unique name. I want the file to be read on the server and saved to the desktop of the user accessing the website. Instead the folder is created on the webserver and copied there. I found one post from Microsoft which indicated that was correct behavior.

Other than sending the file to the brower and then having user save each file separately or using FTP I have not been able to find any solution.


Here is the section of my code. Any suggestions would be helpful.

                                        try
                                        {
                                            rowsDtOracle = dtOracle.Rows.Count;
                                            int x = 0;

                                            WebClient Client = new WebClient ();
                                            //Client.DownloadFile("http://i.stackoverflow.com/Content/Img/stackoverflow-logo-250.png", @"C:\folder\stackoverflowlogo.png");
                                           
                                            while (x < (rowsDtOracle))
                                            {
                                                AttachmentFileName = dtOracle.Rows[x]["VendorFileName"].ToString();
                                                string l_HeaderID = Request.QueryString["HeaderID"].ToString();
                                                string l_DocID = dtOracle.Rows[x]["VendorFileId"].ToString();
                                                string l_AttFileName = dtOracle.Rows[x]["VendorFileName"].ToString();
                                                string l_RFXName = "";

                                                l_varResult = connOracle.GetAttachmentFileVendorOracle(l_HeaderID, l_DocID, m_UserID.ToString(), ref AttachmentFileName, ref l_AttFileName, ref l_RFXName);

                                                bool folderExists = Directory.Exists(@"D:\folder\" + l_RFXName);

                                                if (!folderExists)
                                                {
                                                    try
                                                    {
                                                        Directory.CreateDirectory(@"D:\folder\" + l_RFXName);
                                                    }
                                                    catch (Exception ex)
                                                    {
                                                        Response.Write(ex.ToString());
                                                        //throw;
                                                        lblFail.Visible = true;
                                                        btnExit.Visible = true;
                                                    }
                                                }
                                                try
                                                {
                                                    Client.DownloadFile("htts://xx.xx.xx.xx/Attachments/Download/" + l_RFXName + "/" + AttachmentFileName, @"D:\folder\" + l_RFXName + "\\" + AttachmentFileName); //BF Buyer Test
                                                }
                                                catch (Exception ex)
                                                {
                                                    Response.Write(ex.ToString());
                                                    //throw;
                                                    lblFail.Visible = true;
                                                    btnExit.Visible = true;
                                                }

                                                x++;
                                            }
                                        }
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

Paul MacDonaldDirector, Information SystemsCommented:
There's no way to force a file to be pushed to the client.  Can you imagine the security implications of that?

Your only real option is to offer the visitor a list of links (or ZIP up the files and offer the visitor a single link), and let them download the file(s) themselves.  You can emulate the visitor clicking the link, and just offer them the download dialog, but you can't force them to actually do the download.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
fenbi01Author Commented:
Yes, I understand the security implications. I mostly needed validation that this cannot be done. But I hadn't thought of zipping the files so they only have to do one download. I will give that a try. I want to leave this open for just a little while to see if there any more responses. Otherwise I will accept and close.
0
Paul MacDonaldDirector, Information SystemsCommented:
You could write a program that runs on the client and checks a web site or web service for files to download.  Since the application is running on the client itself, and running as the logged-in user, there's no security conflict.  That's the only other solution I can imagine.
0
Christopher KileCommented:
Ouch!  I'm afraid I didn't make my earlier statement clear enough:  when I said the function was for downloading from the server to the client, I should have made clear that it had to be executed on the client.  paulmacd certainly made that clear, and his suggestion is the only way that would work.  However, you'd have to have the code running in a program on your client workstation, which may not be practicable to install on any of your clients that will need it.  

I'm afraid that you're right, the answer to your question is, the way you're trying to do it now won't work, ever.
0
fenbi01Author Commented:
Thank you for the suggestions. I am pursuing the .zip file and will provide the user a link to open and download the files.
0
fenbi01Author Commented:
Am pursing the zip file solution. Thank you for the responses.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Applications

From novice to tech pro — start learning today.