I'm working with .net 4.0 in asp.net.
I have folder on web server having some pdf file, I display its (File Name) Name in gridview then i want to do "when i click on Item in grid view then it open that pdf file and generate url with file in browser."
I'm using Following Code
GridViewRow row = (GridViewRow)((LinkButton)e.CommandSource).Parent.Parent;
LinkButton hk = (LinkButton)gvFiles.Rows[row.RowIndex].FindControl("lnkbtnTitleView");
string s = Server.MapPath("~/AppName/App_" + dtFiles.Rows[0]["ENewsLetterID"].ToString() + "_1.PDF");
hk.Attributes.Add("onclick","window.open('"+s+"')");
Add ashx handler to your website, that will send pdf as content back to client. Add links to gridview, that will reference to this handler.
If the PDF file already exists simply put direct link:
string s = string.Format("/AppName/App_{0}_1.PDF", dtFiles.Rows[0]["ENewsLetterID"]);
And add window name _blank:
hk.Attributes.Add("onclick", string.Format("window.open('{0}', '_blank');", s));
Otherwise please give more details: how the PDF should be generated?
Related
I have a classic ASP question.
I need to show images on my webpage.
But because of the security reasons, I cannot simply put all of my images in the images folder in my website folder and I need to put them outside of my website folder.
For example, my website folder is located at:
C:\Inetpub\wwwroot\mysite\
But I need to put images (which I want to show on my web pages) at:
C:\images\
I am trying to use ADODB.stream object to pull the images using ASP vb codes as shown below:
<%
Response.ContentType = "image/png"
Set adoStream = Server.CreateObject("ADODB.Stream")
adoStream.Open
adoStream.Type = 1
FPath = "C:\images\1.png"
adoStream.LoadFromFile FPath
Response.BinaryWrite adoStream.Read
adoStream.Close
Set adoStream = Nothing
Response.End
%>
When I launch this webpage in internet explorer, the page shows a File Download window/message for downloading the image file "1.png" rather than displaying the image on the web page.
How can I fix the code to show the image on the web page rather than downloading the image file?
That code generates an image as the return type, so there is no HTML to display the image in, if you call this code directly say it's called image.asp then you would do something like this in another page that displays HTML.
<img src="image.asp" />
This will call your code and output the raw image binary as this is what <img> expects.
If you want to produce multiple images from the file system or database pass a querystring parameter such as ?id=yourimage and change the code to select different images.
I need to show a generated pdf file in a new browser window for asp.net web forms after clicking a button. Here is the sample code for opening new window inside the click event handler-
string url = string.Format("report/RptMoneyReceipt.aspx?FN={0}", "StudentMoneyReceipt" + ".pdf");
string script = "<script type='text/javascript'>window.open('" + url + "','pdf')</script>";
this.ClientScript.RegisterStartupScript(this.GetType(), "script", script);
The code works fine in google chrome. But in firefox after creating a new browser window the browser always downloads the .aspx file instead of showing the pdf.
Q.1. When a image file is uploaded via AjaxUplaoder of CuteWebUI.Uploader it saves file like this
persisted.057fe17e-9707-4f3a-91b7-250239b19c2f.10.JPG.resx
in which "10.jpg" is Image file name and Other "persisted.057fe17e-9707-4f3a-91b7-250239b19c2f.10.JPG.resx" I dont know what is this?
Kindly help me to extract file name from this given format "persisted.057fe17e-9707-4f3a-91b7-250239b19c2f.10.JPG.resx" so that I can show image on Image Control of ASP.Net that is uploaded image file via this Ajax Uploader. This ajax uploader's property 'args.filename' gives file name on 'FileUploaded' event.
look here for the solution of your problem: http://ajaxuploader.com/document/scr/html/How-to-save-uploaded-file.htm
After submitting a form, the user is presented with a link to a pdf document.
The link is straight to the document, it is not streamed.
If the user right-clicks and chooses 'save link as,' the document saves and opens fine. However, if the user just clicks on the link, the browser takes a very long time to respond (I'm going to guess it's 3 minutes) and then adobe reader gives the following error:
"the file is damaged and could not be repaired"
This is in Chrome v5, ASP.NET 3.5 and the link is returned inside an UpdatePanel.
it depends on browser settings that are configured for PDF Links. If you change the settings in broweser, you will get the download dialog.
Mozilla Firefox
Open Mozilla Firefox
Click Tools and then Options
Within the Options window click Applications
Select the Content Type you wish to adjust. For example, if you want to change how a .PDF file opens in Firefox, select Adobe Acrobat Document.
In the Action section, change the action to how you wish to open the file. If you want to download .PDF files instead of opening them, select Save file.
Internet Explorer:
You have to right click and click save target as to download.
The other option is, create a seperate asp.net and write below code to download the PDF
private void Page_Load(object sender, System.EventArgs e)
{
//Set the appropriate ContentType.
Response.ContentType = "Application/pdf";
//Get the physical path to the file.
string FilePath = MapPath("acrobat.pdf");
//Write the file directly to the HTTP content output stream.
Response.WriteFile(FilePath);
Response.End();
}
I've had this issue before and the cause was the PDF itself.
Adobe has a slew of causes for this: http://kb2.adobe.com/cps/328/328233.html
FWIW, my PDf issue was solved by opening the PDF in Adobe and going to Document -> Reduce File Size -> Make Compatible with Version 7. (current version - 2)
i want select folder using asp.net , when i click browse button it will open file selection dialog.
There is no html control for folder selection - so this is not possible with ASP.Net.
You Can Add:
1- Folder Browser Dialog (For Folder)
and use it Like This:
`if(folderBrowserDialog1.ShowDialog() != DialogResult.Cancel)
string str = DialogFolderBrows.SelectedPath;`
2- Open File Dialog (For File)
and use it Like This:
`if(openFileDialog1.ShowDialog() != DialogResult.Cancel)
string str = DialogOpenFile.FileName;`