private bool UploadEventFile(int EventPeriodID, bool checkFile) { int FileId; bool UploadStatus = false; if ((UploadFile.PostedFile != null) && (UploadFile.PostedFile.ContentLength > 0)) { BusinessServices.Event objEvent = new BusinessServices.Event(); int OrganisationID = UserContext.UserData.OrgID; string SaveDir = Server.MapPath(@"\General") + @"\CPDEvent\" + UserContext.UserData.OrgID.ToString(); //Check that the directory exists - if it doesn't then create it if (!Directory.Exists(SaveDir)) { Directory.CreateDirectory(SaveDir); } try { HttpFileCollection hfc = Request.Files; for (int i = 0; i < hfc.Count; i++) { HttpPostedFile hpf = hfc[i]; if (hpf.ContentLength > 0) { System.IO.FileInfo file = new System.IO.FileInfo(hpf.FileName); string fname = file.Name.Remove((file.Name.Length - file.Extension.Length)); fname = fname + "~" + DateTime.Now.ToString("ddMMyyyyhhmmss") + file.Extension; hpf.SaveAs(SaveDir + @"\" + fname); objEvent.EventPeriodID = EventPeriodID; objEvent.FileName = fname; FileId = objEvent.AddEventFile(objEvent); } } } catch (Exception ex) { //log exception to event log ErrorHandler.ErrorLog el = new ErrorHandler.ErrorLog(ex, ErrorLevel.High, "Usercpdevent.aspx.cs", "UploadEventFile", ex.Message); //display friendly message to user lblMessage.Text = ResourceManager.GetString("UploadFail"); lblMessage.CssClass = "WarningMessage"; } } else { lblMessage.Text = ResourceManager.GetString("NoUploadFile"); lblMessage.CssClass = "WarningMessage"; } return(UploadStatus); }