triplebd69
asked on
Reload Web Form
I have web form where I am opening a pdf file on the client like so, and all is well.
string FilePath = @"\\Path\Report.pdf";
WebClient User = new WebClient();
HttpResponse response = HttpContext.Current.Respon se;
response.AddHeader("Conten t-Disposit ion", "attachment;filename=\"" + FilePath + "\"");
byte[] data = User.DownloadData(FilePath );
response.BinaryWrite(data) ;
response.Flush();
response.SuppressContent = true;
Now I need to refresh the the page, I tried Response.Redirect("page.as px"), but that doesn't work.
Can anyone help get the page to reload?
Thanks
string FilePath = @"\\Path\Report.pdf";
WebClient User = new WebClient();
HttpResponse response = HttpContext.Current.Respon
response.AddHeader("Conten
byte[] data = User.DownloadData(FilePath
response.BinaryWrite(data)
response.Flush();
response.SuppressContent = true;
Now I need to refresh the the page, I tried Response.Redirect("page.as
Can anyone help get the page to reload?
Thanks
Hey man,
I'm not sure what is the full scenario and when the pdf should be opened.
However, if you are executing the code on page load, then add a pdfFlag in the QueryString, which will indicate whether you are just loading the page normally or want to open a pdf. So, refreshing the page should be as simple as Response.Redirect("page.as px") without the flag QueryString.
I'm not sure what is the full scenario and when the pdf should be opened.
However, if you are executing the code on page load, then add a pdfFlag in the QueryString, which will indicate whether you are just loading the page normally or want to open a pdf. So, refreshing the page should be as simple as Response.Redirect("page.as
ASKER
M. Tariq,
It is not in the page load, it is in a private method, any ideas on that scenario?
It is not in the page load, it is in a private method, any ideas on that scenario?
It would be helpful if you demonstrate how you call the function and when (including the code snippet would be better and better).
ASKER
Sorry about the formatting EE doesn't seem to like tabs. I need to to a response redirect either at the bottom of btnPrint_Click or bottom of PrintReport, At least that is my thought, I am open to other ideas.
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
FillDropDowns();
}
if (txtBOmNumber.Text != null && ddlSupplier.SelectedIndex > 0 && ddlCarrier.SelectedIndex > 0)
{
btnPrint.Enabled = true;
}
}
catch (Exception)
{
throw;
}
}
protected void btnPrint_Click(object sender, EventArgs e)
{
try
{
int bol = Convert.ToInt32(txtBOmNumb er.Text);
int supplier = Convert.ToInt32(ddlSupplie r.Selected Value);
int carrier = Convert.ToInt32(ddlCarrier .SelectedV alue);
PrintReport(bol, supplier, carrier);
Either here Response.Redirect(“default .aspx”);
}
catch (Exception)
{
}
}
private void PrintReport(int bol, int supplier, int carrier)
{
try
{
cry.Load(Server.MapPath("~ /Reports/C rystalRepo rt1.rpt")) ;
SqlDataAdapter da = new SqlDataAdapter("PrintBOL", con);
da.SelectCommand.CommandTy pe = CommandType.StoredProcedur e;
da.SelectCommand.Parameter s.Add("@BO L", SqlDbType.Int).Value = bol;
da.SelectCommand.Parameter s.Add("@Su pplier", SqlDbType.Int).Value = supplier;
da.SelectCommand.Parameter s.Add("@Ca rrier", SqlDbType.Int).Value = carrier;
var dt = new DataTable();
da.Fill(dt);
cry.SetDataSource(dt);
ExportOptions CrExportOptions;
DiskFileDestinationOptions CrDiskFileDestinationOptio ns = new DiskFileDestinationOptions ();
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptio ns.DiskFil eName = @"\\pri-fs01\vol1\Test\BOL Report.pdf ";
CrExportOptions = cry.ExportOptions;
{
CrExportOptions.ExportDest inationTyp e = ExportDestinationType.Disk File;
CrExportOptions.ExportForm atType = ExportFormatType.PortableD ocFormat;
CrExportOptions.Destinatio nOptions = CrDiskFileDestinationOptio ns;
CrExportOptions.FormatOpti ons = CrFormatTypeOptions;
}
cry.PrintOptions.NoPrinter = true;
cry.Export();
string FilePath = @"\\pri-fs01\vol1\Test\BOL Report.pdf ";
WebClient User = new WebClient();
HttpResponse response = HttpContext.Current.Respon se;
response.AddHeader("Conten t-Disposit ion", "attachment;filename=\"" + FilePath + "\"");
byte[] data = User.DownloadData(FilePath );
response.BinaryWrite(data) ;
response.Flush();
response.SuppressContent = true;
Or here Response.Redirect(“default .aspx”);
}
catch (Exception)
{
throw;
}
}
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (!IsPostBack)
{
FillDropDowns();
}
if (txtBOmNumber.Text != null && ddlSupplier.SelectedIndex > 0 && ddlCarrier.SelectedIndex > 0)
{
btnPrint.Enabled = true;
}
}
catch (Exception)
{
throw;
}
}
protected void btnPrint_Click(object sender, EventArgs e)
{
try
{
int bol = Convert.ToInt32(txtBOmNumb
int supplier = Convert.ToInt32(ddlSupplie
int carrier = Convert.ToInt32(ddlCarrier
PrintReport(bol, supplier, carrier);
Either here Response.Redirect(“default
}
catch (Exception)
{
}
}
private void PrintReport(int bol, int supplier, int carrier)
{
try
{
cry.Load(Server.MapPath("~
SqlDataAdapter da = new SqlDataAdapter("PrintBOL",
da.SelectCommand.CommandTy
da.SelectCommand.Parameter
da.SelectCommand.Parameter
da.SelectCommand.Parameter
var dt = new DataTable();
da.Fill(dt);
cry.SetDataSource(dt);
ExportOptions CrExportOptions;
DiskFileDestinationOptions
PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
CrDiskFileDestinationOptio
CrExportOptions = cry.ExportOptions;
{
CrExportOptions.ExportDest
CrExportOptions.ExportForm
CrExportOptions.Destinatio
CrExportOptions.FormatOpti
}
cry.PrintOptions.NoPrinter
cry.Export();
string FilePath = @"\\pri-fs01\vol1\Test\BOL
WebClient User = new WebClient();
HttpResponse response = HttpContext.Current.Respon
response.AddHeader("Conten
byte[] data = User.DownloadData(FilePath
response.BinaryWrite(data)
response.Flush();
response.SuppressContent = true;
Or here Response.Redirect(“default
}
catch (Exception)
{
throw;
}
}
recently i'm doing the similar thing to enable my portal to download some files.
you may do that using client side download with this jQuery plugin
https://github.com/johnculviner/jquery.fileDownload
by using this plugin, you can try look for the callback status, and if it's success then do your redirection via javascript.
check the source codes and examples from link above.
hope that make sense.
you may do that using client side download with this jQuery plugin
https://github.com/johnculviner/jquery.fileDownload
by using this plugin, you can try look for the callback status, and if it's success then do your redirection via javascript.
check the source codes and examples from link above.
hope that make sense.
ASKER
This looks like what I need but I don't know jquery.
ASKER
Below is my aspx page and the changes I made to the code behind, but it still doesn't work.
<asp:Content ID="Content1" ContentPlaceHolderID="head " runat="server">
Set-Cookie: fileDownload=true; path=/pri-fs01/vol1/Test/B OLReport.p df"
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
$(document).on("click", "a.fileDownloadSimpleRichE xperience" , function () {
$.fileDownload($(this).att r('href'), {
preparingMessageHtml: "We are preparing your report, please wait...",
failMessageHtml: "There was a problem generating your report, please try again."
});
return false; //this is critical to stop the click event which will trigger a normal file download!
});
});
</script>
</asp:Content>
protected void btnPrint_Click(object sender, EventArgs e)
{
try
{
SaveData();
int bol = Convert.ToInt32(txtBOmNumb er.Text);
int supplier = Convert.ToInt32(ddlSupplie r.Selected Value);
int carrier = Convert.ToInt32(ddlCarrier .SelectedV alue);
PrintReport(bol, supplier, carrier);
HttpContext.Current.Respon se.SetCook ie(new HttpCookie("fileDownload", "true") { Path = "/pri-fs01/vol1/Test/BOLRe port.pdf" });
}
catch (Exception)
{
}
}
<asp:Content ID="Content1" ContentPlaceHolderID="head
Set-Cookie: fileDownload=true; path=/pri-fs01/vol1/Test/B
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(function () {
$(document).on("click", "a.fileDownloadSimpleRichE
$.fileDownload($(this).att
preparingMessageHtml: "We are preparing your report, please wait...",
failMessageHtml: "There was a problem generating your report, please try again."
});
return false; //this is critical to stop the click event which will trigger a normal file download!
});
});
</script>
</asp:Content>
protected void btnPrint_Click(object sender, EventArgs e)
{
try
{
SaveData();
int bol = Convert.ToInt32(txtBOmNumb
int supplier = Convert.ToInt32(ddlSupplie
int carrier = Convert.ToInt32(ddlCarrier
PrintReport(bol, supplier, carrier);
HttpContext.Current.Respon
}
catch (Exception)
{
}
}
Man,
What I know is using [response.End()] will end the execution of the page life cycle, which you are not using, so I'm not sure why the next block of code doesn't execute. However, you can call the print function asynchronously via JavaScript and on success you can redirect to whatever page you want.
What I know is using [response.End()] will end the execution of the page life cycle, which you are not using, so I'm not sure why the next block of code doesn't execute. However, you can call the print function asynchronously via JavaScript and on success you can redirect to whatever page you want.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
you want to do it via client side Javascript or via server side asp.net (C# or vb.net?) code behind?