protected void btnPictureUpload_Click(object sender, EventArgs e) { #region Upload if (!FileUploadPictures.HasFile) { } else { string fileName = ""; string ext = ""; string dbFileName = ""; if (FileUploadPictures.HasFile) { string tempstr = Request.QueryString["id"].ToString(); string[] typeArray = FileUploadPictures.FileName.Split('.'); ext = "." + typeArray[typeArray.Length - 1]; fileName = Server.MapPath("images") + "/" + tempstr + ext; dbFileName = "images/" + tempstr + ext; int number = 1; fileName = Server.MapPath("images") + "/" + tempstr + number.ToString() + ext; dbFileName = "images/" + tempstr + number.ToString() + ext; while (File.Exists(fileName)) { number++; fileName = Server.MapPath("images") + "/" + tempstr + number.ToString() + ext; dbFileName = "images/" + tempstr + number.ToString() + ext; } FtpWebRequest request; string folderName = "/goals.ayalasolivan.com/images/"; string absoluteFileName = dbFileName; request = WebRequest.Create(new Uri(string.Format(@"ftp://[email protected]/goals.ayalasolivan.com/" + dbFileName))) as FtpWebRequest; request.Method = WebRequestMethods.Ftp.UploadFile; request.UseBinary = true; request.UsePassive = true; request.KeepAlive = true; request.Credentials = new NetworkCredential("hectorhaas2", "6470060aA@"); request.ConnectionGroupName = "group"; byte[] buffer = FileUploadPictures.FileBytes; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); requestStream.Flush(); Goals gi = new Goals(Request.QueryString["id"].ToString()); gi.UploadPicture(Session["GoalOwner"].ToString(), txtPictureComment.Text, dbFileName); } } #endregion txtPictureComment.Text = ""; //reloadPics populatePicturesTable(); }