private void OpenFile(int fileID, int versionNumber, string strMode) { FileController ctrl = new FileController(); File file; File requestedFile = ctrl.Get(fileID); if (versionNumber == -1) { if (requestedFile.ItemType == 1) //file, don't need version of link { file = ctrl.GetCurrentVersion(fileID); } else { file = requestedFile; //set open to requested file } } else { file = ctrl.GetVersion(fileID, versionNumber); } FileConfigurationController configCtrl = new FileConfigurationController(); List<FileConfiguration> configs = configCtrl.GetItems(PortalId) as List<FileConfiguration>; if (file != null) { if (requestedFile.CanSee(UserId, PortalId, PortalSettings.AdministratorRoleId, true)) { if (file.ItemType == 2) //hyperlink { #region "Audit" //Audit: Create Item AuditController ctrlAudit = new AuditController(); Audit viewAudit = new Audit() { EventDate = System.DateTime.Now, EventDetails = "", EventName = "Opened Link", FileID = requestedFile.ID, UserID = UserId }; ctrlAudit.Create(viewAudit); #endregion Response.Redirect(file.LinkURL); } if (file.ItemType == 1) //file { #region "Audit" //Audit: Create Item AuditController ctrlAudit = new AuditController(); Audit viewAudit; if (versionNumber == -1) { viewAudit = new Audit() { EventDate = System.DateTime.Now, EventDetails = "", EventName = "Downloaded", FileID = requestedFile.ID, UserID = UserId }; } else { viewAudit = new Audit() { EventDate = System.DateTime.Now, EventDetails = "Version: " + file.VersionNumber, EventName = "Downloaded Version", FileID = requestedFile.ID, UserID = UserId }; } ctrlAudit.Create(viewAudit); #endregion bool canOpenFileType = false; switch (file.FileType.ToLower()) { case "text/plain": canOpenFileType = true; break; case "text/html": canOpenFileType = true; break; case "text/xml": canOpenFileType = true; break; case "image/gif": canOpenFileType = true; break; case "image/jpeg": canOpenFileType = true; break; case "image/tiff": canOpenFileType = true; break; case "image/bmp": canOpenFileType = true; break; case "image/png": canOpenFileType = true; break; } if (strMode == "Open" && canOpenFileType == true) { Response.Clear(); Response.ClearHeaders(); Response.ClearContent(); Response.ContentType = file.FileType; Response.AddHeader("Content-Length", file.FileLength.ToString()); //Response.Flush(); //Response.AppendHeader("content-disposition", String.Format("inline; filename={0}.{1}", requestedFile.Name, file.Extension)); //Set the appropriate ContentType. //Response.ContentType = file.FileType; //Get the physical path to the file. string FilePath = MapPath(configs[0].FilesLocation + file.AttachmentPath); //Write the file directly to the HTTP content output stream. Response.WriteFile(FilePath); } else { Response.Clear(); //Response.ClearHeaders(); //Response.ClearContent(); Response.ContentType = file.FileType; Response.AddHeader("Content-Length", file.FileLength.ToString()); //Response.Flush(); Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}.{1}", requestedFile.Name, file.Extension)); Response.Flush(); Response.TransmitFile(configs[0].FilesLocation + file.AttachmentPath); } //Response.Flush(); Response.End(); } } else { //Response.Redirect(Globals.NavigateURL("TabId", "", "WarningMessage=You do not have permission to the requested object.")); ShowUserErrorMessage("You do not have permission to the requested object.", ModuleId); } } else { //Response.Redirect(Globals.NavigateURL("TabId", "", "WarningMessage=The requested object does not exist.")); ShowUserErrorMessage("The requested object does not exist.", ModuleId); } }