I have one button on my partial view,I want to open pdf file on click of button
<button type="button" class="CleanButton" name="button" onclick="ValidateFaxReports('/Verification/PreviewFax','faxReportsComments','FaxReports');">
Preview Fax
</button>
Onclick of the button I need to call javascript function, to check some validation,
'/Verification/PreviewFax' is Url, faxReportsComments is my form Id, FaxReports is id of div which I am using in main view.
Here is my function
private string ViewReport(string file)
{
string errorMessage = string.Empty;
byte[] buffer = null;
try
{
if (file.ToLower().Contains(".enc"))
{
buffer = VOEI.DAL.Crypto.DecryptBinaryFileToByteArray(file);
file = file.ToLower().Replace(".enc", String.Empty);
}
else
{
FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
BinaryReader binReader = new BinaryReader(fs);
buffer = binReader.ReadBytes((int)fs.Length);
binReader.Close();
fs.Close();
}
}
catch (Exception e)
{
errorMessage = e.ToString();
return errorMessage;
}
try
{
Response.Clear();
Response.Buffer = true;
Response.ClearHeaders();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment; filename=" + System.IO.Path.GetFileName(file) + "");
Response.ContentType = "Application/pdf";
Response.BinaryWrite(buffer);
Response.End();
}
finally
{
}
return errorMessage;
}
But it's not working, I don't know why?
Am I missing something?
Rachana