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

Last Reply on May 19, 2015 01:42 AM By TheGunners

Posted 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.

http://www.aspsnippets.com/Articles/Upload-files-and-images-without-page-PostBack-Refresh-Reload-in-ASPNet.aspx

Posted 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;
            try
            {

                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);
                fs.Close();

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

 


Posted 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

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html