public void LoadDisplay(File file) { IWebContext _webcontext = new WebContext(); UserSession _usersession = new UserSession(); if (_usersession.CurrentUser != null) { if (_webcontext.AccountID > 0 && _usersession.CurrentUser.AccountID != _webcontext.AccountID) { if (file.IsPublicResource == true) { Image1.ImageUrl = "~/Photo/ProfileAvatar.aspx?FileID=" + file.FileID; Name.Text = file.FileName; Date.Text = file.CreateDate.ToString(); Desc.Text = "File Share by"+ file.AccountID; FileID.Text = file.FileID.ToString(); Ispublic.Checked = true; LoadFriend(); } else div1.Visible = false; } else { Image1.ImageUrl = "~/Photo/ProfileAvatar.aspx?FileID=" + file.FileID; Name.Text = file.FileName; Date.Text = file.CreateDate.ToString(); Desc.Text = "File Share by" + file.AccountID; FileID.Text = file.FileID.ToString(); Ispublic.Checked = file.IsPublicResource; LoadFriend(); } } }
protected void Page_Load(object sender, EventArgs e) { //_profileRepository = new ProfileRepository(); _fr = new FileRepository(); _userSession = new UserSession(); _accountRepository = new AccountRepository(); _webContext = new WebContext(); if (_userSession.LoggedIn && _userSession.CurrentUser != null) { account = _userSession.CurrentUser; file = _fr.GetFileByID(fileID); } //show the appropriate image if (file != null) { //Response.Clear(); Response.ContentType = "jpg"; Response.BinaryWrite(file.ContentFile.ToArray()); } }
public Folder GetFolderByFileID(File file) { using (SPKTDataContext dc = conn.GetContext()) { long folderid = (dc.Files.Where(f => f.DefaultFolderID == file.FileID).FirstOrDefault()).DefaultFolderID; return GetFolderByID(folderid); } }
public void Shared(Account ac, Account acby, File file) { AccountFileShare asf = new AccountFileShare(); asf.AccountByID = acby.AccountID; asf.AccountID = ac.AccountID; asf.FileID = file.FileID; _af.Save(asf); }
public void DeleteFile(File file) { using (SPKTDataContext dc = conn.GetContext()) { Folder folder = dc.Folders.Where(f => f.FolderID == file.DefaultFolderID).FirstOrDefault(); DeleteFileFromFileSystem(folder, file); dc.Files.Attach(file, true); dc.Files.DeleteOnSubmit(file); dc.SubmitChanges(); } }
public string GetImageByID(Int64 ImageID, File.Sizes Size) { return _fileService.GetFullFilePathByFileID(ImageID, Size); }
private void DeleteFileFromFileSystem(Folder folder, File file) { string path = ""; switch (file.FileTypeID) { case 1: case 2: case 7: path = "Photos\\"; break; case 3: case 4: path = "Audios\\"; break; case 5: case 8: case 6: path = "Videos\\"; break; } string fullPath = _webContext.FilePath + "Files\\" + path + folder.CreateDate.Year.ToString() + folder.CreateDate.Month.ToString() + "\\"; if (System.IO.Directory.Exists(fullPath)) { if (System.IO.File.Exists(fullPath + file.FileSystemName + "__o." + file.Extension)) System.IO.File.Delete(fullPath + file.FileSystemName + "__o." + file.Extension); if (System.IO.File.Exists(fullPath + file.FileSystemName + "__t." + file.Extension)) System.IO.File.Delete(fullPath + file.FileSystemName + "__t." + file.Extension); if (System.IO.File.Exists(fullPath + file.FileSystemName + "__s." + file.Extension)) System.IO.File.Delete(fullPath + file.FileSystemName + "__s." + file.Extension); if (System.IO.File.Exists(fullPath + file.FileSystemName + "__m." + file.Extension)) System.IO.File.Delete(fullPath + file.FileSystemName + "__m." + file.Extension); if (System.IO.File.Exists(fullPath + file.FileSystemName + "__l." + file.Extension)) System.IO.File.Delete(fullPath + file.FileSystemName + "__l." + file.Extension); if (System.IO.Directory.GetFiles(fullPath).Count() == 0) System.IO.Directory.Delete(fullPath); } }
public Int64 SaveFile(File file) { using (SPKTDataContext dc = conn.GetContext()) { if (file.FileID > 0) { dc.Files.Attach(file, true); } else { file.CreateDate = DateTime.Now; dc.Files.InsertOnSubmit(file); } dc.SubmitChanges(); } return file.FileID; }
public List<Int64> UploadPhotos(Int32 FileTypeID, Int32 AccountID, HttpFileCollection Files, Int64 AlbumID) { List<Int64> result = new List<long>(); Folder folder = _folderRepository.GetFolderByID(AlbumID); saveToFolder = _webContext.FilePath + "Files\\"; sizesToMake.Add("T", sizeTiny); sizesToMake.Add("S", sizeSmall); sizesToMake.Add("M", sizeMedium); sizesToMake.Add("L", sizeLarge); switch (FileTypeID) { case 1: saveToFolder += "Photos\\"; break; case 2: saveToFolder += "Videos\\"; break; case 3: saveToFolder += "Audios\\"; break; } //make sure the directory is ready for use saveToFolder += folder.CreateDate.Year.ToString() + folder.CreateDate.Month.ToString() + "\\"; if (!System.IO.Directory.Exists(saveToFolder)) System.IO.Directory.CreateDirectory(saveToFolder); Account account = _accountRepository.GetAccountByID(AccountID); HttpFileCollection uploadedFiles = Files; string Path = saveToFolder; for (int i = 0; i < uploadedFiles.Count; i++) { HttpPostedFile F = uploadedFiles[i]; if (uploadedFiles[i] != null && F.ContentLength > 0) { string folderID = AlbumID.ToString(); string fileType = "1"; string uploadedFileName = F.FileName.Substring(F.FileName.LastIndexOf("\\") + 1); string extension = uploadedFileName.Substring(uploadedFileName.LastIndexOf(".") + 1); Guid guidName = Guid.NewGuid(); string fullFileName = Path + "\\" + guidName.ToString() + "__O." + extension; bool goodFile = true; //create the file File file = new File(); #region "Determine file type" switch (fileType) { case "1": file.FileSystemFolderID = (int)FileSystemFolder.Paths.Pictures; switch (extension.ToLower()) { case "jpg": file.FileTypeID = (int)File.Types.JPG; break; case "gif": file.FileTypeID = (int)File.Types.GIF; break; case "jpeg": file.FileTypeID = (int)File.Types.JPEG; break; default: goodFile = false; break; } break; case "2": file.FileSystemFolderID = (int)FileSystemFolder.Paths.Videos; switch (extension.ToLower()) { case "wmv": file.FileTypeID = (int)File.Types.WMV; break; case "flv": file.FileTypeID = (int)File.Types.FLV; break; case "swf": file.FileTypeID = (int)File.Types.SWF; break; default: goodFile = false; break; } break; case "3": file.FileSystemFolderID = (int)FileSystemFolder.Paths.Audios; switch (extension.ToLower()) { case "wav": file.FileTypeID = (int)File.Types.WAV; break; case "mp3": file.FileTypeID = (int)File.Types.MP3; break; case "flv": file.FileTypeID = (int)File.Types.FLV; break; default: goodFile = false; break; } break; } #endregion file.Size = F.ContentLength; file.AccountID = account.AccountID; file.DefaultFolderID = Convert.ToInt32(folderID); file.FileName = uploadedFileName; file.FileSystemName = guidName; file.Description = ""; file.IsPublicResource = false; if (goodFile) { result.Add(_fileRepository.SaveFile(file)); F.SaveAs(fullFileName); if (Convert.ToInt32(fileType) == ((int)Folder.Types.Picture)) { Resize(F, saveToFolder, guidName, extension); } } } } return result; }
public void UploadFile(HttpPostedFile file,string desc, bool Ispublic) { string extension = Path.GetExtension(file.FileName).ToLower(); string mimetype; byte[] uploadedImage = new byte[file.InputStream.Length]; switch (extension) { case ".png": case ".jpg": case ".gif": mimetype = file.ContentType; break; default: // _view.ShowMessage("We only accept .png, .jpg, and .gif!"); return; } if (file.ContentLength / 1000 < 3000) { SPKTCore.Core.Domain.File fi = new SPKTCore.Core.Domain.File(); fi.AccountID = _userSession.CurrentUser.AccountID; fi.CreateDate = DateTime.Now; if (_webcontext.FolderID > 1) { fi.DefaultFolderID = _webcontext.FolderID; } else { fi.DefaultFolderID = 10; } fi.Description = desc; fi.FileName = file.FileName; fi.FileSystemFolderID = 1; Guid guiname = Guid.NewGuid(); fi.FileSystemName = guiname; string fileType="1"; switch (fileType) { case "1": fi.FileSystemFolderID = (int)FileSystemFolder.Paths.Pictures; switch (extension.ToLower()) { case "jpg": fi.FileTypeID = (int)SPKTCore.Core.Domain.File.Types.JPG; break; case "gif": fi.FileTypeID = (int)SPKTCore.Core.Domain.File.Types.GIF; break; case "jpeg": fi.FileTypeID = (int)SPKTCore.Core.Domain.File.Types.JPEG; break; default: fi.FileTypeID = 1; break; } break; case "2": fi.FileSystemFolderID = (int)FileSystemFolder.Paths.Videos; switch (extension.ToLower()) { case "wmv": fi.FileTypeID = (int)SPKTCore.Core.Domain.File.Types.WMV; break; case "flv": fi.FileTypeID = (int)SPKTCore.Core.Domain.File.Types.FLV; break; case "swf": fi.FileTypeID = (int)SPKTCore.Core.Domain.File.Types.SWF; break; default: fi.FileTypeID=4; break; } break; } fi.FileTypeID = int.Parse(fileType); fi.IsPublicResource = Ispublic; fi.Size = file.ContentLength; file.InputStream.Read(uploadedImage, 0, uploadedImage.Length); fi.ContentFile = uploadedImage; FileRepository fr = new FileRepository(); fr.Save(fi); Folder fo = _for.GetFolderByID(fi.DefaultFolderID); fo.FileDescID = fi.FileID; _for.SaveFolder(fo); if (_webcontext.FolderID == 1) { UserSession _usersession = new UserSession(); StatusUpdate st = new StatusUpdate(); StatusUpdateRepository s = new StatusUpdateRepository(); st.AccountID = _usersession.CurrentUser.AccountID; st.VisibilityLevelID = 1; st.Status = "Tạo Ảnh mới" + fi.FileName; st.SenderID = _usersession.CurrentUser.AccountID; st.FileID = fi.FileID; s.SaveStatusUpdate(st); } } else { // _view.ShowMessage("Ảnh của bạn quá lớn!"); } }