Esempio n. 1
0
        void grdHistory_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (!(e.CommandArgument is Int32))
            {
                return;
            }

            int archiveID = Convert.ToInt32(e.CommandArgument);

            switch (e.CommandName)
            {
            case "restore":
                SharedFile.RestoreHistoryFile(archiveID, this.upLoadPath, this.historyPath);
                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();
                }

                break;
            }
        }