private void GrdNotesDeleteAttachment(int libraryFileId, int refId) { // Button delete functionality if (libraryFileId != 0) { ServiceInformationServiceNote model = new ServiceInformationServiceNote(serviceInformationTDS); model.UpdateLibraryFilesId(int.Parse(hdfServiceId.Value), refId, null, "", ""); LibraryFilesGateway libraryFilesGateway = new LibraryFilesGateway(libraryTDSForServices); libraryFilesGateway.DeleteByLibraryFilesId(libraryFileId); ViewState["update"] = "no"; Session["serviceInformationTDS"] = serviceInformationTDS; Session["libraryTDSForServices"] = libraryTDSForServices; grdNotes.DataBind(); grdCosts.DataBind(); } }
// //////////////////////////////////////////////////////////////////////// // METHODS // private void ProcessUpload2(int serviceId, int refId, int companyId) { LibraryFilesGateway libraryFilesGateway = new LibraryFilesGateway(); try { //... Set the default path to store uploaded files. AppSettingsReader appSettingReader = new AppSettingsReader(); string websitePath = appSettingReader.GetValue("WebsitePath", typeof(System.String)).ToString(); string filename = ""; //... Get the extension of file string[] shortFilename = nuifAttachment.FileName.Split(new char[] { '.' }); string ext = "." + shortFilename[shortFilename.Length - 1]; bool exit = false; while (!exit) { StringBuilder builder = new StringBuilder(); Random rand = new Random(); char ch; for (int i = 0; i < 8; i++) { ch = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * rand.NextDouble() + 65))); builder.Append(ch); } filename = builder.ToString(); filename = filename + ext; libraryFilesGateway.LoadByFileName(filename, companyId); if (libraryFilesGateway.Table.Rows.Count > 0) { exit = false; } else { exit = true; } } string pathFull = websitePath + "\\Files\\LF_DGHOUGDH\\Library\\"; //... Save the file nuifAttachment.MoveTo(Path.Combine(pathFull, filename), MoveToOptions.Overwrite); LibraryFiles libraryFiles = new LibraryFiles(libraryTDSForServices); libraryFiles.Insert(filename, tbxDescription.Text, nuifAttachment.FileName, null, Convert.ToInt32(ViewState["libraryCategoriesId"]), Convert.ToInt32(hdfLoginId.Value), int.Parse(Session["companyID"].ToString()), nuifAttachment.FileContent.Length.ToString()); //Note: COMPANY_ID ServiceInformationServiceNote model = new ServiceInformationServiceNote(serviceInformationTDS); model.UpdateLibraryFilesId(serviceId, refId, 0, nuifAttachment.FileName, filename); int refIdCost = Convert.ToInt32(ViewState["refIdCost"].ToString()); if (refIdCost > 0) { ServiceInformationServiceCost modelCost = new ServiceInformationServiceCost(serviceInformationTDS); modelCost.UpdateLibraryFilesId(serviceId, refIdCost, nuifAttachment.FileName, filename); } Session["libraryTDSForServices"] = libraryTDSForServices; if (Request.QueryString["source_page"] == "services_edit.aspx") { Session["serviceInformationTDS"] = serviceInformationTDS; } else { Session["serviceInformationTDSForManagerTool"] = serviceInformationTDS; } } catch (Exception ex) { } }