public string UpdateReferance(string image, bool check, bool checkBanner, string customerName, int id) { //FTP Folder name. Leave blank if you want to upload to root folder. string ftpFolder = "/Files/Image"; string imageType = ImageUpload.GetFileType(image); string FileIconeName = Guid.NewGuid().ToString(); byte[] fileBytes = ImageUpload.Parse(image); string Fullftp = "ftp://demoproje.site/httpdocs/Files/Image/" + FileIconeName + "." + imageType; string httpAdres = "http://demoproje.site/Files/Image/" + FileIconeName + "." + imageType; FtpWebRequest reqFtp = (FtpWebRequest) FtpWebRequest.Create(Fullftp); reqFtp.Credentials = new NetworkCredential("u9172314", "OImu28B6"); reqFtp.KeepAlive = false; reqFtp.Method = WebRequestMethods.Ftp.UploadFile; reqFtp.UseBinary = true; reqFtp.UsePassive = true; try { using (Stream strm = reqFtp.GetRequestStream()) { strm.Write(fileBytes, 0, fileBytes.Length); strm.Close(); } } catch (Exception ex) { } Reference reference = new Reference(); { reference.CustomerName = customerName; reference.Id = id; reference.Image = httpAdres; reference.IsBanner = checkBanner; reference.IsActive = check; bool result = reference.UpdateReferance(reference); } return(JsonConvert.SerializeObject("File uploaded successfully")); }
public string SaveSubCategory(SubCategory sub, int categoryId, string image) { string imageType = ImageUpload.GetFileType(image); string FileIconeName = Guid.NewGuid().ToString(); byte[] fileBytes = ImageUpload.Parse(image); string Fullftp = "ftp://demoproje.site/httpdocs/Files/Image/" + FileIconeName + "." + imageType; string httpAdres = "http://demoproje.site/Files/Image/" + FileIconeName + "." + imageType; FtpWebRequest reqFtp = (FtpWebRequest) FtpWebRequest.Create(Fullftp); reqFtp.Credentials = new NetworkCredential("u9172314", "OImu28B6"); reqFtp.KeepAlive = false; reqFtp.Method = WebRequestMethods.Ftp.UploadFile; reqFtp.UseBinary = true; reqFtp.UsePassive = true; try { using (Stream strm = reqFtp.GetRequestStream()) { strm.Write(fileBytes, 0, fileBytes.Length); strm.Close(); } } catch (Exception ex) { } bool result = false; SubCategory subCategory = new SubCategory(); { subCategory.Name = sub.Name; subCategory.IsActive = sub.IsActive; subCategory.CategoryId = categoryId; subCategory.Image = httpAdres; result = subCategory.AddSubCategory(subCategory); } string message = result ? "İşlem Tamamlandı." : "Hata Oluştu."; return(JsonConvert.SerializeObject(message)); }
public string SaveProduct(Product product, string image, string pdf, CategoryDTO subCategory) { string FullPdfHttp = ""; string httpAdres = ""; if (image != null) { string FileIconeName = Guid.NewGuid().ToString(); byte[] fileBytes = ImageUpload.Parse(image); string imageType = ImageUpload.GetFileType(image); string Fullftp = "ftp://demoproje.site/httpdocs/Files/Image/" + FileIconeName + "." + imageType; httpAdres = "http://demoproje.site/Files/Image/" + FileIconeName + "." + imageType; FtpWebRequest reqFtp = (FtpWebRequest) FtpWebRequest.Create(Fullftp); reqFtp.Credentials = new NetworkCredential("u9172314", "OImu28B6"); reqFtp.KeepAlive = false; reqFtp.Method = WebRequestMethods.Ftp.UploadFile; reqFtp.UseBinary = true; reqFtp.UsePassive = true; try { using (Stream strm = reqFtp.GetRequestStream()) { strm.Write(fileBytes, 0, fileBytes.Length); strm.Close(); } } catch (Exception ex) { } } if (pdf != null) { string FileIconeName = Guid.NewGuid().ToString(); string imagepdf = ImageUpload.GetFileType(pdf); byte[] pdfByte = ImageUpload.Parse(pdf); string FullPdf = "ftp://demoproje.site/httpdocs/Files/Image/" + imagepdf + "." + "pdf"; FullPdfHttp = "http://demoproje.site/Files/Image/" + FileIconeName + "." + "pdf"; FtpWebRequest reqFtp = (FtpWebRequest) FtpWebRequest.Create(FullPdf); reqFtp.Credentials = new NetworkCredential("u9172314", "OImu28B6"); reqFtp.KeepAlive = false; reqFtp.Method = WebRequestMethods.Ftp.UploadFile; reqFtp.UseBinary = true; reqFtp.UsePassive = true; try { using (Stream strm = reqFtp.GetRequestStream()) { strm.Write(pdfByte, 0, pdfByte.Length); strm.Close(); } } catch (Exception ex) { string messages = ex.Message; } } bool result = false; Product pro = new Product(); { pro.Name = product.Name; pro.CategoryId = subCategory.SubCategoryId; pro.Description = product.Description; pro.Description2 = product.Description2; pro.AplicationAreas = product.AplicationAreas; pro.ManufacturingPlace = product.ManufacturingPlace; pro.Image = httpAdres; pro.SubName = product.SubName; pro.Pdf = FullPdfHttp; pro.IsActive = product.IsActive; result = pro.AddProduct(pro); } string message = result ? "İşlem Tamamlandı." : "Hata Oluştu."; return(JsonConvert.SerializeObject(message)); }