protected void filAddExtension_Upload(object sender, FileUploadEventArgs e) { //get the uploaded file and its metadata HttpPostedFile postedFile = e.PostedFile; string filepath = postedFile.FileName; string filename = filepath.Substring(filepath.LastIndexOf('\\') + 1); if (ValidateFile(filename)) { //separate the file extension from the filename string fileExt = System.IO.Path.GetExtension(filename); string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(filename); int contentLength = postedFile.ContentLength; string contentType = postedFile.ContentType; System.IO.BinaryReader reader = new System.IO.BinaryReader(postedFile.InputStream); byte[] bytes = new byte[contentLength]; reader.Read(bytes, 0, contentLength); //store the file into the data store Utility.DocumentStorage documentStorageObject = Utility.DocumentStorage.GetDocumentStorageObject(_itatSystem.DocumentStorageType); documentStorageObject.RootPath = _itatSystem.DocumentStorageRootPath; string objectId = documentStorageObject.SaveDocument(fileNameWithoutExt, fileExt, bytes); //add metadata about the extension to the template object Business.Extension extension = new Kindred.Knect.ITAT.Business.Extension(); extension.FileName = filename; extension.ObjectID = objectId; _template.Extensions.Add(extension); //update the form InitializeForm(_template.Extensions.Count - 1); //select newly added row (last row in the grid) } }
protected virtual void OnUpload(FileUploadEventArgs e) { EventHandler<FileUploadEventArgs> temp = Upload; if (temp != null) temp(this, e); }
protected void filNewAttachment_OnUpload(object sender, FileUploadEventArgs e) { //get the uploaded file and its metadata HttpPostedFile postedFile = e.PostedFile; string filepath = postedFile.FileName; string filename = filepath.Substring(filepath.LastIndexOf('\\') + 1); if (ValidateFile(filename)) { //separate the file extension from the filename string fileExt = System.IO.Path.GetExtension(filename); string fileNameWithoutExt = System.IO.Path.GetFileNameWithoutExtension(filename); int contentLength = postedFile.ContentLength; string contentType = postedFile.ContentType; System.IO.BinaryReader reader = new System.IO.BinaryReader(postedFile.InputStream); byte[] bytes = new byte[contentLength]; reader.Read(bytes, 0, contentLength); //store the file into the data store string documentStoreId = string.Empty; try { Utility.DocumentStorage documentStorageObject = Utility.DocumentStorage.GetDocumentStorageObject(_itatSystem.DocumentStorageType); documentStorageObject.RootPath = _itatSystem.DocumentStorageRootPath; documentStoreId = documentStorageObject.SaveDocument(fileNameWithoutExt, fileExt, bytes); } catch (ArgumentException ex) { if (ex.Message.Contains(Utility.Names._EM_UnrecognizedExtension)) { BasePage p = Page as BasePage; if (p == null) throw new Exception("The AttachmentControl object must be used on a page that derives from BasePage."); p.RegisterAlert("Unrecognized file extension on attachment."); } else throw; } //store a reference to the document in the DocumentCache table if (!string.IsNullOrEmpty(documentStoreId)) { Data.Document.AddCachedDocument(Guid.NewGuid(), _managedItem.ManagedItemID, documentStoreId, filepath, "", ""); //create attachment and add it to the managed item Business.Attachment newAttachment = new Kindred.Knect.ITAT.Business.Attachment(Guid.NewGuid(), filepath, "", documentStoreId, new Business.DocumentType(""), false); _managedItem.Attachments.Add(newAttachment); } } }
protected void btnUpload_Command(object sender, CommandEventArgs e) { FileUploadEventArgs fuea = new FileUploadEventArgs(inputFile.PostedFile); OnUpload(fuea); }