public Object GetThumbnail(String uniqueName) { var rootPath = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles"); var FileDTO = FileBO.GetFileByUniqueName(uniqueName); var fileFullPath = Path.Combine(rootPath, FileDTO.UniqueName + FileDTO.FileExt); ShellFile shellFile = ShellFile.FromFilePath(fileFullPath); Bitmap shellThumb = shellFile.Thumbnail.MediumBitmap; if (FileDTO != null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); byte[] file = ImageToBytes(shellThumb); // Call to private function ImageToBytes MemoryStream ms = new MemoryStream(file); response.Content = new ByteArrayContent(file); response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(FileDTO.ContentType); response.Content.Headers.ContentDisposition.FileName = FileDTO.Name; return(response); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound); return(response); } }
public bool Insert(List <HttpPostedFileBase> file) { try { this.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); if (file == null) { return(false); } var fileBo = new FileBO(); foreach (var httpPostedFileBase in file) { if (fileBo.Insert(this.ConnectionHandler, httpPostedFileBase) == Guid.Empty) { throw new Exception("خطایی ذخیره فایل وجود دارد"); } } this.ConnectionHandler.CommitTransaction(); return(true); } catch (KnownException knownException) { this.ConnectionHandler.RollBack(); Log.Save(knownException.Message, LogType.ApplicationError, knownException.Source, knownException.StackTrace); throw new KnownException(knownException.Message, knownException); } catch (Exception ex) { this.ConnectionHandler.RollBack(); Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public Object DownloadFile(String uname) { var rootPath = System.Web.HttpContext.Current.Server.MapPath("~/UploadedFiles"); var dto = FileBO.GetFileByUniqueName(uname); if (dto != null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); var fileFullPath = System.IO.Path.Combine(rootPath, dto.UniqueName + dto.FileExt); byte[] file = System.IO.File.ReadAllBytes(fileFullPath); System.IO.MemoryStream ms = new System.IO.MemoryStream(file); response.Content = new ByteArrayContent(file); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new MediaTypeHeaderValue(dto.ContentType); response.Content.Headers.ContentDisposition.FileName = dto.Name; return(response); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound); return(response); } }
public ActionResult Create(Product product, HttpPostedFileBase file) { if (ModelState.IsValid) { product.ProductId = Guid.NewGuid(); var image = new FileBO().Insert(file); product.FileId = image.FileId; product.File = image; db.Product.Add(product); if (db.SaveChanges() > 0) { if (Session["Color"] != null) { var colorList = (List <Color>)Session["Color"]; foreach (var item in colorList) { item.ProductId = product.ProductId; db.Color.Add(item); db.SaveChanges(); } } return(RedirectToAction("Index")); } } return(View(product)); }
public void UploadFile(int uid, int pid) { if (HttpContext.Current.Request.Files.Count > 0) { try { foreach (var fileName in HttpContext.Current.Request.Files.AllKeys) { HttpPostedFile file = HttpContext.Current.Request.Files[fileName]; if (file != null) { FileDTO dto = new FileDTO(); dto.Name = file.FileName; dto.FileExt = VirtualPathUtility.GetExtension(file.FileName); dto.UploadedOn = DateTime.Now; dto.CreatedBy = uid; dto.ParentFolderId = pid; dto.UniqueName = Guid.NewGuid().ToString(); dto.FileSizeInKB = file.ContentLength / 1024; dto.ContentType = file.ContentType; var rootPath = HttpContext.Current.Server.MapPath("~/UploadedFiles"); var fileSavePath = System.IO.Path.Combine(rootPath, dto.UniqueName + dto.FileExt); file.SaveAs(fileSavePath); FileBO.Save(dto); } } } catch (Exception e) { } } }
public override bool Insert(BookPart bookPart) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); try { var file = new File() { Content = bookPart.Text.ConvertTextToHtml(), ContentType = "image/png", Extension = ".png", FileName = bookPart.Name, Id = Guid.NewGuid(), }; var imageId = new FileBO().InsertFile(base.ConnectionHandler, file); if (imageId == null && imageId == Guid.Empty) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } bookPart.Image = imageId; bookPart.Id = Guid.NewGuid(); bookPart.PublishDate = DateTime.Now.ShamsiDate(); if (!new BookPartBO().Insert(base.ConnectionHandler, bookPart)) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new KnownException(ex.Message, ex); } }
public Object DownloadFile(String uniqueName) { // Physical path of root folder var rootPath = HttpContext.Current.Server.MapPath("~/Files"); // Find file from DB using unique name var dto = FileBO.GetFileInfoByUN(uniqueName); if (dto != null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); var filefullpath = Path.Combine(rootPath, dto.UniqueName + dto.Extension); byte[] file = File.ReadAllBytes(filefullpath); MemoryStream ms = new MemoryStream(file); response.Content = new ByteArrayContent(file); response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue(dto.FileType); response.Content.Headers.ContentDisposition.FileName = dto.Name; return(response); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound); return(response); } }
public FileUpload upload(Stream file, string fileName, string type, int userId, string ipAddress, string bucketName, ref string errorMessage) { try { FileBO bo = new FileBO(); string fName = fileName; string fPath = genFilePathRandomFileName(bucketName, ref fName); var f = new FileUpload() { fileName = fName, ipAddress = ipAddress, type = type, userId = userId, uploadDate = new DateTime() }; if (this.upload(file, fName, bucketName, ref errorMessage)) { f = bo.addFile(f); f.fileName = GenerateHTTPFilePath(f.fileName, JSettings.GoogleCloudStorage.Bucket.Large); } return(f); } catch (Exception ex) { errorMessage = ex.Message; return(null); } }
public bool Delete(Guid id) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var fileBO = new FileBO(); var bookPartBO = new BookPartBO(); try { var bookPart = bookPartBO.Get(base.ConnectionHandler, id); if (bookPart.Image != null && bookPart.Image != Guid.Empty) { if (!fileBO.Delete(base.ConnectionHandler, bookPart.Image)) { throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است"); } } if (!bookPartBO.Delete(base.ConnectionHandler, bookPart)) { throw new Exception("خطایی در حذف اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new Exception(ex.Message, ex); } }
public bool Update(Book book, IFormFile image, IFormFile pdf) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var fileBO = new FileBO(); try { if (image != null) { if (book.Image != null) { if (!fileBO.Delete(base.ConnectionHandler, book.Image)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } } var imageId = fileBO.Insert(base.ConnectionHandler, image, book.ImageFile); if (imageId == null && imageId == Guid.Empty) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } book.Image = imageId; } if (pdf != null) { var exte = Path.GetExtension(pdf.FileName).ToLower(); if (Path.GetExtension(pdf.FileName).ToLower() != ".pdf") { throw new Exception("فایل بارگزاری شده برای کتاب باید با پسوند pdf باشد"); } if (book.PDF != null) { if (!fileBO.Delete(base.ConnectionHandler, book.PDF)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } } var pdfId = fileBO.Insert(base.ConnectionHandler, pdf, book.PdfFile); if (pdfId == null && pdfId == Guid.Empty) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } book.PDF = pdfId; } if (!new BookBO().Update(base.ConnectionHandler, book)) { throw new Exception("خطایی در درج اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new Exception(ex.Message, ex); } }
private string genFilePathRandomFileName(string bucketName, ref string fileName) { string fPath = string.Empty; FileBO bo = new FileBO(); do { fileName = bo.RandomFileName(fileName); fPath = genPhysicalUploadFilePath(fileName, bucketName); } while (bo.isExist(fileName)); return(fPath); }
public ActionResult Create([Bind(Include = "SliderId,Title,Description,FileId,IsMainSlider,LangId")] Slider slider, HttpPostedFileBase file) { slider.SliderId = Guid.NewGuid(); var image = new FileBO().Insert(file); slider.FileId = image.FileId; slider.File = image; if (new SliderBO().Insert(slider)) { return(RedirectToAction("Index")); } return(View(slider)); }
public void File() { L_FileUpload data = new L_FileUpload() { fileName = "TEST", ipAddress = "123", macAddress = "ABC", type = "PRD", userId = 1 }; FileBO bo = new FileBO(); //var res = bo.addFile(data); }
public ActionResult Create(OfferBanner offerBanner, HttpPostedFileBase file) { File image = new FileBO().Insert(file); offerBanner.FileId = image.FileId; //offerBanner.File = image; db.OfferBanners.Add(offerBanner); if (db.SaveChanges() > 0) { return(RedirectToAction("Index")); } return(View(offerBanner)); }
public ActionResult Create([Bind(Include = "WallPaperId,Title,Position,Description")] WallPaper WallPaper, HttpPostedFileBase file) { WallPaper.WallPaperId = Guid.NewGuid(); var image = new FileBO().Insert(file); WallPaper.FileId = image.FileId; WallPaper.File = image; db.WallPaper.Add(WallPaper); if (db.SaveChanges() > 0) { return(RedirectToAction("Index")); } return(View(WallPaper)); }
public ActionResult Create([Bind(Include = "Title,Content,LangId")] News news, HttpPostedFileBase imageid, HttpPostedFileBase videoid) { var image = new FileBO().NewsInsert(imageid); var video = new FileBO().NewsInsert(videoid); news.ImageId = image.FileId; news.VideoId = video.FileId; news.SaveDate = Utility.CurrentDate(DateTime.Now, news.LangId); db.News.Add(news); if (db.SaveChanges() > 0) { return(RedirectToAction("Index")); } return(View(news)); }
public bool Update(Brands brands, HttpPostedFileBase image) { bool isedit = true; if (image == null) { throw new Exception("لطفا عکس مطلب را انتخاب کنید"); } File file = new FileBO().Get(brands.FileId); if (file == null) { file = new File { Context = new byte[image.ContentLength] }; isedit = false; } else { file.Context = new byte[image.ContentLength]; } image.InputStream.Read(file.Context, 0, image.ContentLength); file.ContextType = image.ContentType; file.Title = image.FileName; file.FileSize = image.ContentLength / 1024; if (isedit) { if (!new FileBO().Update(file)) { throw new Exception("خطا در ویرایش تصویر"); } } else { if (!new FileBO().Insert(file)) { throw new Exception("خطا در ویرایش تصویر"); } brands.FileId = file.Id; } return(base.Update(brands)); }
public override bool Update(BookPart bookPart) { base.ConnectionHandler.StartTransaction(IsolationLevel.ReadUncommitted); var fileBO = new FileBO(); try { var file = new File() { Content = bookPart.Text.ConvertTextToHtml(), Extension = ".png", ContentType = "image/png", FileName = bookPart.Name, }; if (bookPart.Image != null) { if (!fileBO.Delete(base.ConnectionHandler, bookPart.Image)) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } } var imageId = fileBO.InsertFile(base.ConnectionHandler, file); if (imageId == null && imageId == Guid.Empty) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } bookPart.Image = imageId; if (!new BookPartBO().Update(base.ConnectionHandler, bookPart)) { throw new KnownException("خطایی در درج اطلاعات کتاب رخ داده است"); } base.ConnectionHandler.CommitTransaction(); return(true); } catch (Exception ex) { base.ConnectionHandler.RollBack(); throw new KnownException(ex.Message, ex); } }
public bool Update(Guid fileId, File fileoptions) { try { var file = new FileBO().Get(this.ConnectionHandler, fileId); if (file == null) { return(false); } if (fileoptions != null) { if (fileoptions.MaxSize > 0) { var i = file.Content.Length / 1024; if (i > fileoptions.MaxSize) { throw new Exception(Resources.FileManager.Filesizeislargerthanallowedsize); } } if (!string.IsNullOrEmpty(fileoptions.FileName)) { file.FileName = fileoptions.FileName; } if (fileoptions.FolderId.HasValue) { file.FolderId = fileoptions.FolderId; } } return(new FileBO().Update(this.ConnectionHandler, file)); } catch (KnownException knownException) { Log.Save(knownException.Message, LogType.ApplicationError, knownException.Source, knownException.StackTrace); throw new KnownException(knownException.Message, knownException); } catch (Exception ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public bool Update(Content content, HttpPostedFileBase image) { if (image != null) { File oldfile = new FileBO().Get(content.FileId); File file = null; if (oldfile == null) { file = new File(); } else { file = oldfile; } file.Context = new byte[image.ContentLength]; image.InputStream.Read(file.Context, 0, image.ContentLength); file.ContextType = image.ContentType; file.Title = image.FileName; file.FileSize = image.ContentLength / 1024; if (oldfile == null) { if (!new FileBO().Insert(file)) { throw new Exception("خطا در ویرایش تصویر"); } content.FileId = file.Id; } else { if (!new FileBO().Update(file)) { throw new Exception("خطا در ویرایش تصویر"); } } } return(base.Update(content)); }
public Guid Insert(HttpPostedFileBase file, File fileoptions) { try { var insert = new FileBO().Insert(this.ConnectionHandler, file, fileoptions); if (insert == Guid.Empty) { throw new Exception("خطایی ذخیره فایل وجود دارد"); } return(insert); } catch (KnownException knownException) { Log.Save(knownException.Message, LogType.ApplicationError, knownException.Source, knownException.StackTrace); throw new KnownException(knownException.Message, knownException); } catch (Exception ex) { Log.Save(ex.Message, LogType.ApplicationError, ex.Source, ex.StackTrace); throw new KnownException(ex.Message, ex); } }
public void GetMetaData(int uid, int pid) { FolderDTO main = FolderBO.GetFolder(uid, pid); List <FolderDTO> folderList = FolderBO.GetAllMainFoldersByUser(uid, pid); String dest = "D:\\Extras\\MetaData.pdf"; var writer = new PdfWriter(dest); var pdf = new PdfDocument(writer); var document = new Document(pdf); document.Add(new Paragraph("Meta Information of Folder: " + main.Name)); document.Add(new Paragraph("Name: " + main.Name)); document.Add(new Paragraph("Type: Folder")); document.Add(new Paragraph("Size: None")); if (main.ParentFolderId == -1) { document.Add(new Paragraph("Parent: Root")); } else { FolderDTO folder1 = FolderBO.GetFolder(main.CreatedBy, main.ParentFolderId); document.Add(new Paragraph("Parent: " + folder1.Name)); } int count = folderList.Count; Queue <FolderDTO> foldersQueue = new Queue <FolderDTO>(); for (int i = 0; i < count; i++) { foldersQueue.Enqueue(folderList[i]); } List <FileDTO> fileList = FileBO.GetAllFiles(uid, pid); count = fileList.Count; Queue <FileDTO> filesQueue = new Queue <FileDTO>(); for (int i = 0; i < count; i++) { filesQueue.Enqueue(fileList[i]); } while (foldersQueue.Count > 0) { FolderDTO folder = foldersQueue.Dequeue(); document.Add(new Paragraph("Name: " + folder.Name)); document.Add(new Paragraph("Type: Folder")); document.Add(new Paragraph("Size: None")); if (folder.ParentFolderId == -1) { document.Add(new Paragraph("Parent: Root")); } else { FolderDTO folder1 = FolderBO.GetFolder(folder.CreatedBy, folder.ParentFolderId); document.Add(new Paragraph("Parent: " + folder1.Name)); } document.Add(new Paragraph("")); folder.ParentFolderId = folder.Id; folderList = FolderBO.GetAllMainFoldersByUser(folder.CreatedBy, folder.ParentFolderId); count = folderList.Count; for (int i = 0; i < count; i++) { foldersQueue.Enqueue(folderList[i]); } fileList = FileBO.GetAllFiles(folder.CreatedBy, folder.ParentFolderId); count = fileList.Count; for (int i = 0; i < count; i++) { filesQueue.Enqueue(fileList[i]); } } while (filesQueue.Count > 0) { FileDTO file = filesQueue.Dequeue(); document.Add(new Paragraph("Name: " + file.Name)); document.Add(new Paragraph("Type: File")); document.Add(new Paragraph("Size: " + file.FileSizeInKB + " KB")); if (file.ParentFolderId == -1) { document.Add(new Paragraph("Parent: Root")); } else { FolderDTO folder1 = FolderBO.GetFolder(uid, file.ParentFolderId); document.Add(new Paragraph("Parent: " + folder1.Name)); } document.Add(new Paragraph("")); } document.Add(new Paragraph("")); document.Close(); return; }
public Object GenerateMetadata(int folderid, int ownerid) { var ParentFolderDTO = FolderBO.GetFolderInfoByID(folderid); var ChildFolderDTO = FolderBO.GetAllFolderInfo(folderid, ownerid); var FileDTO = FileBO.GetAllFileInfo(folderid); // Generating Guid String fileName = Guid.NewGuid().ToString() + ".pdf"; // Physical path of root folder var rootPath = HttpContext.Current.Server.MapPath("~/Files"); var filefullpath = Path.Combine(rootPath, fileName); // Making pdf file var writer = new PdfWriter(filefullpath); var pdf = new PdfDocument(writer); var document = new Document(pdf); document.Add(new Paragraph("Name: " + ParentFolderDTO.Name)); document.Add(new Paragraph("Type: Folder")); document.Add(new Paragraph("Size: NILL")); if (ParentFolderDTO.ParentFolderID == 0) { document.Add(new Paragraph("Parent: ROOT")); } else { document.Add(new Paragraph("Parent: " + FolderBO.GetParentName(ParentFolderDTO.ParentFolderID))); } document.Add(new Paragraph(Environment.NewLine)); //Child Folders info if (ChildFolderDTO.Any(item => item.ID != 0)) { document.Add(new Paragraph(" ******* Sub Directories Information ******")); document.Add(new Paragraph(Environment.NewLine)); foreach (var item in ChildFolderDTO) { document.Add(new Paragraph("Name: " + item.Name)); document.Add(new Paragraph("Type: Folder")); document.Add(new Paragraph("Size: NILL")); document.Add(new Paragraph("Parent: " + ParentFolderDTO.Name)); document.Add(new Paragraph(Environment.NewLine)); } } if (FileDTO.Any(item => item.ID != 0)) { // Files information document.Add(new Paragraph("******* File Information ********")); document.Add(new Paragraph(Environment.NewLine)); foreach (var item in FileDTO) { document.Add(new Paragraph("Name: " + item.Name)); document.Add(new Paragraph("Type: " + item.FileType)); document.Add(new Paragraph("Size: " + (item.Size) + " KB")); document.Add(new Paragraph("Parent: " + ParentFolderDTO.Name)); document.Add(new Paragraph(Environment.NewLine)); } } document.Close(); if (fileName != null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); byte[] file = File.ReadAllBytes(filefullpath); MemoryStream ms = new MemoryStream(file); response.Content = new ByteArrayContent(file); response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment"); response.Content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/pdf"); response.Content.Headers.ContentDisposition.FileName = fileName; return(response); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound); return(response); } }
public List <FileDTO> GetAllFiles(int uid, int pid) { return(FileBO.GetAllFiles(uid, pid)); }
public int UploadFile(int parentid, int ownerid) { var dto = new FileDTO(); int rev = 0; /* * string rootPath = HttpContext.Current.Server.MapPath("~/Files"); * * var provider = new MultipartMemoryStreamProvider(); * await Request.Content.ReadAsMultipartAsync(provider); * * // extract file name and file contents * var fileNameParam = provider.Contents[0].Headers.ContentDisposition.Parameters * .FirstOrDefault(p => p.Name.ToLower() == "filename"); * string fileName = (fileNameParam == null) ? "" : fileNameParam.Value.Trim('"'); * byte[] file = await provider.Contents[0].ReadAsByteArrayAsync(); * * // Here you can use EF with an entity with a byte[] property, or * // an stored procedure with a varbinary parameter to insert the * // data into the DB * * dto.Name = fileName.Substring(0, fileName.IndexOf('.')); * dto.Extension = fileName.Substring(fileName.IndexOf('.')+1); * dto.Size = (file.Length / 1024); * dto.UploadOn = DateTime.Now; * dto.IsActive = true; * * //var result = string.Format("Received '{0}' with length: {1}", fileName, file.Length/1024); * return dto; */ if (HttpContext.Current.Request.Files.Count > 0) { try { foreach (var fileName in HttpContext.Current.Request.Files.AllKeys) { HttpPostedFile file = HttpContext.Current.Request.Files[fileName]; if (file != null) { dto.Name = file.FileName; dto.Extension = Path.GetExtension(file.FileName); dto.IsActive = true; dto.UploadOn = DateTime.Now; dto.ParentFolderID = parentid; dto.Size = (file.ContentLength / 1024); dto.FileType = file.ContentType; dto.UniqueName = Guid.NewGuid().ToString(); // Getting physical path of folder where to save uploaded file var rootPath = HttpContext.Current.Server.MapPath("~/Files/"); var fileSavePath = Path.Combine(rootPath, dto.UniqueName + dto.Extension); // Save the uploaded file to 'Files' directory file.SaveAs(fileSavePath); // Save File Meta data in Database rev = FileBO.SaveFileInfo(dto, ownerid); } } } catch (Exception ex) { } } return(rev); }
public Object DeleteFile(string uniqueName) { return(FileBO.DeleteFile(uniqueName)); }
public int DeleteFile(int fid) { return(FileBO.DeleteFile(fid)); }
public ActionResult ShowImage(int id) { File model = new FileBO().Get(id); return(File(model.Context, "image/jpg"));; }
public override bool Delete(params object[] keys) { var obj = new FileBO().Get(this.ConnectionHandler, keys); return(obj == null || new FileBO().Delete(this.ConnectionHandler, keys)); }