示例#1
0
        void grdHistory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            int archiveID = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName)
            {
            case "restore":
                //SharedFile.RestoreHistoryFile(archiveID, this.upLoadPath, this.historyPath);
                SharedFilesHelper.RestoreHistoryFile(archiveID, fileSystem, virtualSourcePath, virtualHistoryPath);
                WebUtils.SetupRedirect(this, Request.RawUrl);
                break;

            case "deletehx":
                SharedFilesHelper.DeleteHistoryFile(archiveID, fileSystem, virtualHistoryPath);
                SharedFile.DeleteHistory(archiveID);

                WebUtils.SetupRedirect(this, Request.RawUrl);
                break;

            case "download":

                SharedFileHistory historyFile = SharedFile.GetHistoryFile(archiveID);
                if (historyFile != null)
                {
                    string fileType = Path.GetExtension(historyFile.FriendlyName).Replace(".", string.Empty);
                    if (string.Equals(fileType, "pdf", StringComparison.InvariantCultureIgnoreCase))
                    {
                        //this will display the pdf right in the browser
                        Page.Response.AddHeader("Content-Disposition", "filename=" + historyFile.FriendlyName);
                    }
                    else
                    {
                        // other files just use file save dialog
                        Page.Response.AddHeader("Content-Disposition", "attachment; filename=" + historyFile.FriendlyName);
                    }

                    //Page.Response.AddHeader("Content-Length", documentFile.DocumentImage.LongLength.ToString());

                    Page.Response.ContentType  = "application/" + fileType;
                    Page.Response.Buffer       = false;
                    Page.Response.BufferOutput = false;
                    //Response.TransmitFile(historyPath + historyFile.ServerFileName);
                    //Response.End();

                    using (System.IO.Stream stream = fileSystem.GetAsStream(virtualHistoryPath + historyFile.ServerFileName))
                    {
                        stream.CopyTo(Page.Response.OutputStream);
                    }
                    try
                    {
                        Page.Response.End();
                    }
                    catch (System.Threading.ThreadAbortException) { }
                }

                break;
            }
        }
示例#2
0
        public static bool RestoreHistoryFile(
            int historyId,
            IFileSystem fileSystem,
            string virtualSourcePath,
            string virtualHistoryPath)
        {
            bool historyRestored = false;

            if (string.IsNullOrEmpty(virtualSourcePath))
            {
                return(historyRestored);
            }
            if (string.IsNullOrEmpty(virtualHistoryPath))
            {
                return(historyRestored);
            }
            if (fileSystem == null)
            {
                return(historyRestored);
            }


            int      itemId              = 0;
            int      moduleId            = 0;
            string   historyFriendlyName = string.Empty;
            string   historyOriginalName = string.Empty;
            string   historyServerName   = string.Empty;
            DateTime historyUploadDate   = DateTime.Now;
            int      historyUploadUserID = 0;
            int      historyFileSize     = 0;

            using (IDataReader reader = SharedFile.GetHistoryFileAsIDataReader(historyId))
            {
                if (reader.Read())
                {
                    itemId              = Convert.ToInt32(reader["ItemID"]);
                    moduleId            = Convert.ToInt32(reader["ModuleID"]);
                    historyFriendlyName = reader["FriendlyName"].ToString();
                    historyOriginalName = reader["OriginalFileName"].ToString();
                    historyServerName   = reader["ServerFileName"].ToString();
                    historyFileSize     = Convert.ToInt32(reader["SizeInKB"]);
                    historyUploadUserID = Convert.ToInt32(reader["UploadUserID"]);
                    historyUploadDate   = DateTime.Parse(reader["UploadDate"].ToString());
                }
            }

            SharedFile sharedFile = new SharedFile(moduleId, itemId);

            CreateHistory(sharedFile, fileSystem, virtualSourcePath, virtualHistoryPath);

            //File.Move(Path.Combine(historyPath, Path.GetFileName(historyServerName)), Path.Combine(sourcePath, Path.GetFileName(historyServerName)));
            fileSystem.MoveFile(
                VirtualPathUtility.Combine(virtualHistoryPath, historyServerName),
                VirtualPathUtility.Combine(virtualSourcePath, historyServerName),
                true);

            sharedFile.ServerFileName   = historyServerName;
            sharedFile.OriginalFileName = historyOriginalName;
            sharedFile.FriendlyName     = historyFriendlyName;
            sharedFile.SizeInKB         = historyFileSize;
            sharedFile.UploadDate       = historyUploadDate;
            sharedFile.UploadUserId     = historyUploadUserID;
            historyRestored             = sharedFile.Save();
            SharedFile.DeleteHistory(historyId);

            fileSystem.DeleteFile(VirtualPathUtility.Combine(virtualHistoryPath, historyServerName));


            return(historyRestored);
        }