protected void Page_Load(object sender, EventArgs e) { fileType = this.Request.Params["filetype"]; bool newfile = !(int.TryParse(this.Request.Params["file"], out _fileid)); if (!bool.TryParse(this.Request.Params["newFile"], out _isNewFileRequestParam)) { _isNewFileRequestParam = false; } int formid = int.Parse(this.Request.Params["form"]); this.controller = new FormFileController(formid); if (newfile) { Formfile file = this.controller.CreateFile(); // redirect to the correct page Response.Redirect(string.Format("Editor.aspx?file={0}&form={1}&fileType={2}&newFile=true", file.Id, formid, fileType)); } else { this.controller.LoadFile(_fileid); } if (!this.IsPostBack) { this.EditForm.EditableForm = this.controller.EditableForm; } }
public EditableFile(Formfile formFile) : base(formFile) { //pre-populate all the fields, along with any existing records FormfieldCollection allFields = new FormfieldCollection().Where(Formfield.Columns.Formid, this.SymanticForm.Form.Id).Load(); this.relatedFields = new List <EditableField>(); for (int i = 0; i < allFields.Count; i++) { Formrecord candidateRecord = this.FormFile.Formrecords().FirstOrDefault <Formrecord>(record => record.Fieldid == allFields[i].Id); EditableField field; if (candidateRecord != null) { field = new EditableField(candidateRecord); } else { field = new EditableField(allFields[i]); } field.FieldStoringCallback += new EventHandler <EditableFieldStoringCallbackArgs>(HandleEditableFieldStoring); this.relatedFields.Add(field); } /// Sort the fields in field order this.relatedFields = this.relatedFields.OrderBy(field => field.Metadata.FieldOrder).ToList(); }
/// <summary> /// Creates a new file frecords for this form without a specified person. /// </summary> public Formfile CreateFile() { Formfile file = new Formfile(); file.Form = this.Form; file.Save(Utility.GetActiveUsername()); this.LoadFile(file.Id); return(file); }
/// <summary> /// Deletes the file in this form. It is a soft delete unless desotry == true /// </summary> internal void DeleteFile(bool destory) { if (!destory) { this.FormFile.Deleted = true; this.FormFile.Save(Utility.GetActiveUsername()); } else { Formfile.Delete(this.FormFile.Id); } this.FormFile = null; this.relatedFields.Clear(); }
/// <summary> /// Creates a file record for the specified person. /// </summary> public Formfile CreateFile(Person person) { if (this.HasFile(person)) { throw new NotSupportedException("A file already exists for the person"); } Formfile file = new Formfile(); file.Form = this.Form; file.Person = person; file.Save(Utility.GetActiveUsername()); this.LoadFile(file.Id); return(file); }
/// <summary> /// Loads a specific File. Returns null if the file doesn't exist /// </summary> public static ViewableFile GetFile(int id) { Formfile formFile = Formfile.FetchByID(id); ViewableFile file = null; if (formFile != null) { file = new ViewableFile(formFile); } else { throw new Exception("File doesn't exist"); } return(file); }
/// <summary> /// Loads a particular file for this form by it's ID /// </summary> /// <param name="id"></param> public void LoadFile(int id) { this.file = Formfile.FetchByID(id); if (this.file.IsNew) { this.file = null; } if (this.file.Formid != this.Form.Id) { this.file = null; } if (this.file != null) { this.FileLoaded = true; } }
public async Task <IActionResult> Post(List <IFormFile> files) { long sizes = files.Sum(f => f.Length); var filepath = Path.GetTempFileName(); int i = 1; TempData["message"] = null; foreach (var Formfile in files) { if (Formfile.ContentType.ToLower() != "text/plain") { TempData["message"] = "The " + Path.GetFileName(filepath) + " is a wrong file"; break; } else if (Formfile.Length <= 0) { TempData["message"] = "The " + Path.GetFileName(filepath) + " is empty"; break; } else if (Formfile.Length > 1048576) { TempData["message"] = "The " + Path.GetFileName(filepath) + " is too big"; break; } else { var filedest = "/Users/harrydevarakarianingcipto/Codes/ASP.NET/ASP.NET file upload" + i + ".txt"; using (var stream = new FileStream(filedest, FileMode.Create)) { await Formfile.CopyToAsync(stream); } using (var reader = new StreamReader(Formfile.OpenReadStream())) { TempData["message"] = TempData["message"] + "\\n" + await reader.ReadToEndAsync(); } } i++; } return(RedirectToAction("Index")); }
public SymanticFile(Formfile formFile) : this(formFile, new SymanticForm(formFile.Form)) { }
public SymanticFile(Formfile formFile, SymanticForm form) { this.SymanticForm = form; this.FormFile = formFile; }
public ViewableFile(Formfile encapsulatedFormFile) : base(encapsulatedFormFile) { }
internal void EncapsulateFormFile(Formfile encapsulatedFormFile) { this.FormFile = encapsulatedFormFile; this.SymanticForm = new SymanticForm(encapsulatedFormFile.Form); }