Uploading files not working on Shared web Hosting in ASP.Net

on May 11, 2015 04:52 AM

I am using below link to upload files , the code wrking fine on my system with win 8 and studio2012 but when i put code on my hosting with shared hosting package the page giving error . my hosting runs on iis7.5. please help, what to do , what to keep in web.config and what to remove.


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on May 12, 2015 12:38 AM

Even i was facing the same issue with godaddy. U can try Ftp upload.

Below is my code wich may help you.


String sourcefilepath = FileUpload1.FileName; // e.g. “d:/test.docx”
        if (sourcefilepath != null)
            String ftpurl = "Ftp url"; // e.g. ftp://serverip/foldername/foldername
            String ftpusername = "username"; // e.g. username
            String ftppassword = "password"; // e.g. password
            //string filename = Path.GetFileName(sourcefilepath);
            string filename = Path.GetFileName(sourcefilepath);
            string ftpfullpath = ftpurl;

                FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
                ftp.Credentials = new NetworkCredential(ftpusername, ftppassword);

                ftp.KeepAlive = true;
                ftp.UseBinary = true;
                ftp.Method = WebRequestMethods.Ftp.UploadFile;

                FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath(@"~/contact/") + filename, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                //FileStream fs = File.OpenRead(filename);
                byte[] buffer = new byte[fs.Length];
                fs.Read(buffer, 0, buffer.Length);

                Stream ftpstream = ftp.GetRequestStream();
                ftpstream.Write(buffer, 0, buffer.Length);
            catch (Exception exe2)
                Label1.Text = exe2.ToString();


on May 19, 2015 01:42 AM

Hi Eshant,

Hmm... Why you are not trying to upload your files using FTP? It will be more stable. Please test