protected string SaveImage(FileUpload fUpload) { string strDBImagePath = string.Empty; try { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = fUpload.PostedFile.FileName; string FolderName = CommonFn.JaslokNews; string strFileNameOnly = CommonFn.GetFileName(fileName); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly; fUpload.SaveAs(strSaveImagePath); strDBImagePath = CommonFn.DbSave + CommonFn.DbJaslokNewsFolder; strDBImagePath = strDBImagePath + strFileNameOnly; } catch (Exception ex) { throw ex; } return(strDBImagePath); }
protected string SaveImage() { string strDBImagePath = string.Empty; try { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(UploadImages.PostedFile.FileName); string FolderName = CommonFn.BannerFolder; if (!CommonFn.folderExists(strServerPath, FolderName)) { try { CommonFn.CreateFolder(strServerPath, FolderName); } catch { } } string strFileNameOnly = CommonFn.GetFileName(fileName); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly; UploadImages.SaveAs(strSaveImagePath); strDBImagePath = CommonFn.DbSave + CommonFn.DbBannerFolder; strDBImagePath = strDBImagePath + strFileNameOnly; } catch { ; } return(strDBImagePath); }
public void Upload() { ////HttpPostedFile MyFile = Request.Files["MyFile"]; //string fileName = Path.GetFileName(UploadResume.PostedFile.FileName); ViewState["FilePath"] = ""; //for (int i = 0; i < Request.Files.Count; i++) //{ // var myFile = Request.Files[i]; // if (myFile != null && myFile.ContentLength != 0) // { // pathForSaving = Server.MapPath("~/uploadedfiles/"); // string pathForSavingFile = "/uploadedfiles/"; // try // { // string strFileNameOnly = CommonFn.GetFileName(myFile.FileName); // ViewState["FilePath"] = Path.Combine(pathForSavingFile, strFileNameOnly); // string strFileName= Path.Combine(pathForSavingFile, strFileNameOnly); // MyFile = Request.Files[CommonFn.GetFileName(myFile.FileName)]; // MyFile.SaveAs(Path.Combine(pathForSaving, strFileName)); // } // catch (Exception ex) // { // } // } //} string strDBImagePath = string.Empty; try { if (UploadResume.HasFile) { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(UploadResume.PostedFile.FileName); string FolderName = CommonFn.UploadedResumeFolder; string strFileNameOnly = CommonFn.GetFileName(fileName); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly; UploadResume.SaveAs(strSaveImagePath); strDBImagePath = CommonFn.DbSave + CommonFn.DbUploadedResume; strDBImagePath = strDBImagePath + strFileNameOnly; ViewState["FilePath"] = strDBImagePath; } } catch (Exception ex) { } }
protected string SaveImage(string UpFileName, int flcontrolId) { string strDBImagePath = string.Empty; try { if (UpFileName.Length < 1035000) { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(UpFileName); string FileNameWEx = Path.GetFileNameWithoutExtension(fileName); FileNameWEx = objDAEntities.RemoveBadCharForFolder(FileNameWEx); String FileExtension = System.IO.Path.GetExtension(fileName); // listofuploadedfiles.Text = fileName; string FolderName = CommonFn.SeminarGalleryFolder; if (!CommonFn.folderExists(strServerPath, FolderName)) { try { CommonFn.CreateFolder(strServerPath, FolderName); } catch { } } string strFileNameOnly = CommonFn.GetFileName(FileNameWEx); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly + FileExtension; if (flcontrolId == 1) { UploadImages.SaveAs(strSaveImagePath); } else { FileUploadTOPIC.SaveAs(strSaveImagePath); } strDBImagePath = CommonFn.DbSave + CommonFn.DbSeminarGalleryFolder; strDBImagePath = strDBImagePath + strFileNameOnly; } else { lblMessage.CssClass = "errorlbl"; lblMessage.Text = "Images size is more than 1.035 mb!!!"; ViewState["optype"] = "INSERT"; } } catch { lblMessage.CssClass = "errorlbl"; lblMessage.Text = "Something worng!!!!"; ViewState["optype"] = "INSERT"; } return(strDBImagePath); }
protected string SaveImage() { string strDBImagePath = string.Empty; try { if (UploadImages.PostedFile.ContentLength < 1035000) { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(UploadImages.PostedFile.FileName); string FileNameWEx = Path.GetFileNameWithoutExtension(fileName); FileNameWEx = objDAEntities.RemoveBadCharForFolder(FileNameWEx); String FileExtension = System.IO.Path.GetExtension(fileName); //listofuploadedfiles.Text = fileName; if ((FileExtension.ToLower() == ".jpg" || FileExtension.ToLower() == ".png" || FileExtension.ToLower() == ".jpeg" || FileExtension.ToLower() == ".tiff" || FileExtension.ToLower() == ".gif")) { string FolderName = CommonFn.UserGalleryFolder; if (!CommonFn.folderExists(strServerPath, FolderName)) { try { CommonFn.CreateFolder(strServerPath, FolderName); } catch { } } string strFileNameOnly = CommonFn.GetFileName(fileName); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly; UploadImages.SaveAs(strSaveImagePath); strDBImagePath = CommonFn.DbSave + CommonFn.DbUserGalleryFolder; strDBImagePath = strDBImagePath + strFileNameOnly; } } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Images size is more than 1.035 mb!!!');", true); } } catch { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Something worng!!!');", true); } return(strDBImagePath); }
public string savefile(FileUpload Uploadedfile, string folderName, string dbPath) { string rtnPath = null; if (Uploadedfile.HasFile) { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(Uploadedfile.PostedFile.FileName); string FileNameWEx = Path.GetFileNameWithoutExtension(fileName); string strDBImagePath; FileNameWEx = objDAEntities.RemoveBadCharForFolder(FileNameWEx); String FileExtension = System.IO.Path.GetExtension(fileName); // listofuploadedfiles.Text = fileName; // string FolderName = folderName; string strFileNameOnly = CommonFn.GetFileName(FileNameWEx); strSaveImagePath = strServerPath + folderName + "\\" + strFileNameOnly + FileExtension; Uploadedfile.SaveAs(strSaveImagePath); objDAEntities.UserId = 1; if (Uploadedfile.UniqueID == fileUploadJaslokTimes.UniqueID) { objDAEntities.FileName = strFileNameOnly + FileExtension; } // objDAEntities.FilePath = strSaveImagePath; strDBImagePath = CommonFn.DbSave + dbPath; rtnPath = strDBImagePath + "/" + strFileNameOnly + FileExtension; } else { lblMessage.CssClass = "errorlbl"; lblMessage.Text = "Images size is more than 1.035 mb!!!"; ViewState["optype"] = "INSERT"; } return(rtnPath); }
protected string SaveImage() { string strDBImagePath = string.Empty; try { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(UploadImages.PostedFile.FileName); String FileExtension = System.IO.Path.GetExtension(fileName); string FolderName = CommonFn.DoctorFolder; if ((FileExtension.ToLower() == ".jpg" || FileExtension.ToLower() == ".png" || FileExtension.ToLower() == ".jpeg" || FileExtension.ToLower() == ".tiff" || FileExtension.ToLower() == ".gif")) { if (!CommonFn.folderExists(strServerPath, FolderName)) { try { CommonFn.CreateFolder(strServerPath, FolderName); } catch { } } string strFileNameOnly = CommonFn.GetFileName(fileName); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly; UploadImages.SaveAs(strSaveImagePath); strDBImagePath = CommonFn.DbSave + CommonFn.DbDoctorFolder; strDBImagePath = strDBImagePath + strFileNameOnly; } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only Image file allowed!!!');", true); } } catch { //ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Only Image file allowed!!!');", true); } return(strDBImagePath); }
protected void btnSubmit_Click(object sender, EventArgs e) { try { if (fileUploadWNew.PostedFile.FileName != "") { lblfileName.Text = fileUploadWNew.PostedFile.FileName; if (fileUploadWNew.PostedFile.FileName.Length < 1035000) { string strServerPath = Server.MapPath(CommonFn.Image_Save_Path); string strSaveImagePath = string.Empty; string fileName = Path.GetFileName(lblfileName.Text); string FileNameWEx = Path.GetFileNameWithoutExtension(fileName); string strDBImagePath; FileNameWEx = objDAEntities.RemoveBadCharForFolder(FileNameWEx); String FileExtension = System.IO.Path.GetExtension(fileName); // listofuploadedfiles.Text = fileName; string FolderName = CommonFn.WhatsNewFile; if (!CommonFn.folderExists(strServerPath, FolderName)) { try { CommonFn.CreateFolder(strServerPath, FolderName); } catch { } } string strFileNameOnly = CommonFn.GetFileName(FileNameWEx); strSaveImagePath = strServerPath + FolderName + "\\" + strFileNameOnly + "_" + DateTime.Now.Ticks + FileExtension; fileUploadWNew.SaveAs(strSaveImagePath); objDAEntities.WhatsNewId = 0; //objDAEntities.FileName = strFileNameOnly + FileExtension + "_" + DateTime.Now.Ticks; objDAEntities.WhatsNewTitle = txtWhatsNewTitle.Text; objDAEntities.IsActiveWhatsNew = chkFileActive.Checked; objDAEntities.FilePath = strSaveImagePath; objDAEntities.WNSummury = reWhatsNewSummary.Content.Replace(" ", ""); objDAEntities.UserId = 1; strDBImagePath = CommonFn.DbSave + CommonFn.DbWhatsNew; strDBImagePath = strDBImagePath + strFileNameOnly; objBusinessLogic.AddWhatsNew(objDAEntities); lblMessage.CssClass = "successlbl"; lblMessage.Text = "Data saved successfully!!!"; lblMessage.Visible = true; Clear(); //GetWhatsNew(); } else { lblMessage.CssClass = "errorlbl"; lblMessage.Text = "Images size is more than 1.035 mb!!!"; ViewState["optype"] = "INSERT"; lblMessage.Visible = true; } } } catch (Exception ex) { } }