Пример #1
0
        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;
            }
        }
Пример #2
0
        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();
        }
Пример #3
0
        /// <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);
        }
Пример #4
0
 /// <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();
 }
Пример #5
0
        /// <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);
        }
Пример #6
0
        /// <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);
        }
Пример #7
0
 /// <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;
     }
 }
Пример #8
0
        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"));
        }
Пример #9
0
 public SymanticFile(Formfile formFile)
     : this(formFile, new SymanticForm(formFile.Form))
 {
 }
Пример #10
0
 public SymanticFile(Formfile formFile, SymanticForm form)
 {
     this.SymanticForm = form;
     this.FormFile     = formFile;
 }
Пример #11
0
 public ViewableFile(Formfile encapsulatedFormFile)
     : base(encapsulatedFormFile)
 {
 }
Пример #12
0
 internal void EncapsulateFormFile(Formfile encapsulatedFormFile)
 {
     this.FormFile     = encapsulatedFormFile;
     this.SymanticForm = new SymanticForm(encapsulatedFormFile.Form);
 }