public Object getThumbnail(string uniqueName) { fileBA fileBAObj = new fileBA(); fileDTO fileObj = fileBAObj.getFile(uniqueName); var rootPath = HttpContext.Current.Server.MapPath("~/UploadedFiles"); var fileFullPath = System.IO.Path.Combine(rootPath, fileObj.uniqueName + fileObj.fileExt); ShellFile shellFile = ShellFile.FromFilePath(fileFullPath); Bitmap shellThumb = shellFile.Thumbnail.MediumBitmap; if (fileObj != null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); byte[] file = ImageToBytes(shellThumb); 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(fileObj.contentType); response.Content.Headers.ContentDisposition.FileName = fileObj.name; return(response); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound); return(response); } }
public HttpResponseMessage downloadFile(String uniqueName) { fileBA fileBAObj = new fileBA(); fileDTO fileObj = fileBAObj.getFile(uniqueName); var rootPath = HttpContext.Current.Server.MapPath("~/UploadedFiles"); if (fileObj != null) { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK); var fileFullPath = System.IO.Path.Combine(rootPath, fileObj.uniqueName + fileObj.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(fileObj.contentType); response.Content.Headers.ContentDisposition.FileName = fileObj.name; return(response); } else { HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.NotFound); return(response); } }
public fileDTO getFile(String uniqueName) { String connString = @"Data Source=.\SQLEXPRESS2012; Initial Catalog=Assignment8; Integrated Security=True; Persist Security Info=True;"; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); String sqlQuery = "Select * from dbo.files where uniquename='" + uniqueName + "'and isactive='1'"; SqlCommand command = new SqlCommand(sqlQuery, conn); SqlDataReader reader = command.ExecuteReader(); fileDTO fileObj = new fileDTO(); if (reader.Read() == true) { fileObj.id = reader.GetInt32(reader.GetOrdinal("id")); fileObj.name = reader.GetString(reader.GetOrdinal("name")); fileObj.uniqueName = reader.GetString(reader.GetOrdinal("uniquename")); fileObj.parentFolderId = reader.GetInt32(reader.GetOrdinal("parentfolderid")); fileObj.fileExt = reader.GetString(reader.GetOrdinal("fileext")); fileObj.fileSizeinKb = reader.GetInt32(reader.GetOrdinal("filesizeinkb")); if (!reader.IsDBNull(reader.GetOrdinal("contenttype"))) { fileObj.contentType = reader.GetString(reader.GetOrdinal("contenttype")); } else { fileObj.contentType = null; } } return(fileObj); } }
public bool saveFile(fileDTO obj) { fileDAO fileObjDAO = new fileDAO(); if (fileObjDAO.saveFile(obj)) { return(true); } return(false); }
public List <fileDTO> loadFiles() { fileDTO obj = new fileDTO(); obj.createdBy = Convert.ToInt32(System.Web.HttpContext.Current.Request["createdBy"]); obj.parentFolderId = Convert.ToInt32(System.Web.HttpContext.Current.Request["parentFolderId"]); fileBA fileBAObj = new fileBA(); List <fileDTO> fileList = fileBAObj.getAllFiles(obj); return(fileList); }
public bool saveFile(fileDTO obj) { String connString = @"Data Source=.\SQLEXPRESS2012; Initial Catalog=Assignment8; Integrated Security=True; Persist Security Info=True;"; using (SqlConnection conn = new SqlConnection(connString)) { conn.Open(); String sqlQuery = ""; sqlQuery = String.Format(@"INSERT INTO dbo.files(name, uniquename, parentfolderid, fileext, filesizeinkb, createdby, uploadedon, contenttype, isactive) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}',{8})", obj.name, obj.uniqueName, obj.parentFolderId, obj.fileExt, obj.fileSizeinKb, obj.createdBy, DateTime.Now, obj.contentType, 1); SqlCommand command = new SqlCommand(sqlQuery, conn); int rowAffected = command.ExecuteNonQuery(); Console.WriteLine("{0} Row Affected", rowAffected); return(true); } }
public bool addNewFile() { 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 fileObj = new fileDTO(); fileObj.name = file.FileName; fileObj.uniqueName = Guid.NewGuid().ToString(); fileObj.parentFolderId = Convert.ToInt32(System.Web.HttpContext.Current.Request["parentFolderId"]); fileObj.fileExt = Path.GetExtension(file.FileName); fileObj.fileSizeinKb = file.ContentLength / 1024; fileObj.createdBy = Convert.ToInt32(System.Web.HttpContext.Current.Request["createdBy"]); fileObj.contentType = file.ContentType; var rootPath = HttpContext.Current.Server.MapPath("~/UploadedFiles"); var fileSavePath = System.IO.Path.Combine(rootPath, fileObj.uniqueName + fileObj.fileExt); fileBA fileBAObj = new fileBA(); if (fileBAObj.saveFile(fileObj)) { file.SaveAs(fileSavePath); return(true); } } } } catch (Exception ex) { // } } return(false); }
public void getMetaData() { folderDTO obj = new folderDTO(); obj.createdBy = Convert.ToInt32(System.Web.HttpContext.Current.Request["createdBy"]); obj.parentFolderId = Convert.ToInt32(System.Web.HttpContext.Current.Request["parentFolderId"]); folderBA folderBAObj = new folderBA(); List <folderDTO> folderList = folderBAObj.getAllFolders(obj); String dest = "C:\\Users\\Muneeb\\Documents\\Visual Studio 2013\\Projects\\ead_s18_a8_bcsf15m030\\MyDrive\\Web API\\UploadedFiles\\metaInformation.pdf"; var writer = new PdfWriter(dest); var pdf = new PdfDocument(writer); var document = new Document(pdf); int count = folderList.Count; Queue <folderDTO> foldersQueue = new Queue <folderDTO>(); for (int i = 0; i < count; i++) { foldersQueue.Enqueue(folderList[i]); } fileDTO fileObj = new fileDTO(); fileObj.createdBy = Convert.ToInt32(System.Web.HttpContext.Current.Request["createdBy"]); fileObj.parentFolderId = Convert.ToInt32(System.Web.HttpContext.Current.Request["parentFolderId"]); fileBA fileBAObj = new fileBA(); List <fileDTO> fileList = fileBAObj.getAllFiles(fileObj); 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 == 0) { document.Add(new Paragraph("Parent: Root")); } else { folderDTO folder1 = folderBAObj.getFolder(folder); document.Add(new Paragraph("Parent: " + folder1.name)); } document.Add(new Paragraph("")); folder.parentFolderId = folder.id; folderList = folderBAObj.getAllFolders(folder); count = folderList.Count; for (int i = 0; i < count; i++) { foldersQueue.Enqueue(folderList[i]); } fileList = fileBAObj.getAllFilesById(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 == 0) { document.Add(new Paragraph("Parent: Root")); } else { folderDTO folder1 = folderBAObj.getFolderById(file.parentFolderId); document.Add(new Paragraph("Parent: " + folder1.name)); } document.Add(new Paragraph("")); } document.Add(new Paragraph("")); document.Close(); return; }
public List <fileDTO> getAllFiles(fileDTO obj) { fileDAO fileObjDAO = new fileDAO(); return(fileObjDAO.getAllfiles(obj)); }