|
I have Get Method which I am expecting to open a pdf file in a new browser tab, but its not happening - below is the code
public void GetDoc(int id)
{
string fileInfo = "ID=[" + id + "] ";
try
{
var file = this.DomainLogicUnitOfWork.UploadedDocumentManager.GetById(id);
fileInfo = "FILENAME=[" + file.FileName + "]";
Response.Clear();
Response.ContentType = file.FileContentType;
Response.AppendHeader("content-disposition", "attachment; filename=" + file.FileName);
Response.OutputStream.Write(file.DocumentImage, 0, file.DocumentImage.Length);
Response.Output.Flush();
Response.End();
}
catch (Exception ex)
{
LogHandler.LogError(4617, "Error Downloading Document " + fileInfo, ex);
throw ex;
}
}
My url is opening correctly: http://localhost:xcxcxcx/Upload/GetDoc?id=1088 and it gives a warning when click on the start of the browser address and one more thing is the Word and other documents are being downloaded fine - means they are working fine but problem is just with PDF files. Any suggestions or ideas -
thank you all friends.
|
|
|
|
|
There are some browser settings that can control whether or not files are opened in a new tab so you don't have complete control over it.
Also, this code runs in the context of the existing page and will return to the same page. I do not think there is a way to do it with code like this.
You can create a hyperlink and set it to open in a new tab.
You can also change the button or whatever it is that fires this event to open a new window and pass in a url that then calls this code.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
It is fixed by change the AppendHeader as below
if (file.FileContentType.ToLower() != "application/pdf")
Response.AppendHeader("content-disposition", "attachment; filename=" + file.FileName);
But I got another question - is there any way I can let the user when saving the file - give him the file name that has come by default - any help please? Thank you.
|
|
|
|
|
simpledeveloper wrote: Response.AppendHeader("content-disposition", "attachment; filename=" + file.FileName); It's my understand that will make it download as an attachment rather than display inline. If that made it open in a new tab for you, that's good, but like I said I don't think you can control it 100%. Someone's browser settings can change that behavior.
simpledeveloper wrote: give him the file name that has come by default I'm not sure what you mean. In your code you specified a file name.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
ZurdoDev wrote: I'm not sure what you mean. In your code you specified a file name.
I want to give the option when saving file name with the file name that comes with FileInfo object.
ZurdoDev wrote: It's my understand that will make it download as an attachment rather than display inline
OK - nice, is there anyway I can allow the user to download the file rather than opening in a new browser? How can I do that? It will be a great help for me.
simpledeveloper wrote: Response.AppendHeader("content-disposition", "attachment; filename=" + file.FileName);
How can I change this statement for pdf to be able to download? Any help regarding this buddy? It will be a great help - thank you.
|
|
|
|
|
Attachment means it will download. But again, some browsers have settings that can affect that.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
If it is chrome? Is there something we can do it from server side code buddy? Yeah now I am getting it - why isn't it doing it - thanks for helping me my friend.
And just saying I like this - its true
ZurdoDev wrote: Social Media - A platform that makes it easier for the crazies to find each other.
|
|
|
|
|
simpledeveloper wrote: If it is chrome? Sorry, I do not know. It's been years since I worried about this issue so I don't know what the settings look like today.
simpledeveloper wrote: Is there something we can do it from server side I believe the only thing you can do is to add the attachment header info which you already did.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
ZurdoDev wrote: I believe the only thing you can do is to add the attachment header info which you already did.
Yes I did see it - its working fine with IE, its only giving problem with Chrome - so any ideas from other users here also helpful - I will investigate a little bit about it.
|
|
|
|
|
Enclosing within the double quotes resolved the problem like in this one:
Response.AppendHeader("content-disposition", $"attachment; filename=\"{file.FileName}\"");
|
|
|
|
|
Hi...
How I can insert data into gridview without use data source???
|
|
|
|
|
|
Thank you for your answer,
But I don’t want use data source,
I want directly add the data from textbox without use DataTable
|
|
|
|
|
|
The website is working fine now I added MenuLeft.ascx into the folder "C:\WebSite2010\WebMaster\Controls\" when pressing the Rebuild website button with the error "Error: C:\WebSite2010\WebMaster\Controls\MenuTop.ascx.cs(14): error ASPNET: Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl)". Note that the folder "C:\WebSite2010\Controls\" already has a file with the same file name: MenuLeft.ascx now I copy the declaration of 2 files with the same name, how do I change the code ?
in the file: C:\WebSite2010\Controls\MenuLeft.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuLeft.ascx.cs" Inherits="MenuLeft" %>
<%@ Import Namespace="webapp4U" %>
<%@ Register Src="~/Controls/ThuvienHinhAnh.ascx" TagPrefix="uc" TagName="ThuvienHinhAnh" %>
<%@ Register Src="~/Controls/QuangCaoLeft.ascx" TagPrefix="uc" TagName="QuangCaoLeft" %>
<%@ Register Src="~/Controls/WebURL.ascx" TagPrefix="uc" TagName="WebURL" %>
<%@ Register Src="~/Controls/Newsletter.ascx" TagPrefix="uc" TagName="Newsletter" %>
<%@ Register src="DanhMucBDS.ascx" tagname="DanhMucBDS" tagprefix="uc" %>
<%@ Register TagPrefix="webapp4U" Namespace="webapp4U.UI" %>
<table cellspacing="0" cellpadding="0" width="180" border="0">
...
</table>
in the file: C:\WebSite2010\WebMaster\Controls\MenuLeft.ascx
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MenuLeft.ascx.cs" Inherits="MenuLeft" %>
<%@ Import Namespace="webapp4U" %>
<table width="185px" border="0" cellpadding="0" cellspacing="0">
...
</table>
|
|
|
|
|
You need to first understand how code files work and then fix them. I'm not sure how to tell you to fix it because I don't know what you need or don't need. You said you have two files with the same name, so start with removing one or changing the name of one. But then make sure the codefile matches the class.
For example, in what you posted, you need to have a class in the MenuLeft.ascx.cs file that is named MenuLeft.
Just go through your files and get it cleaned up properly.
Social Media - A platform that makes it easier for the crazies to find each other.
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
I have fixed it, thank you for reading my post.
|
|
|
|
|
I am displaying a list of textboxes on top of an image on an ASP .NET Master/Content webpage. The image is the width of the page and has 6 even spaced white blocks. What I am trying to do is put a number in each image box white space using the CSS and HTML below. What is happening is all of the textboxes are being displayed in the same image box which is the first. In the first, the textboxes are only about 2px apart from each other and not spreading across the image 20px apart as defined it the left CSS tag. Why is my style is not correct?
Master:
<style>
.floating_label1 {
position: absolute;
z-index: 200;
top: 65px;
**left: 115px;**
}
.floating_label2 {
position: absolute;
z-index: 200;
top: 65px;
**left: 130px;**
}
.floating_label3 {
position: absolute;
z-index: 200;
top: 65px;
**left: 150px;**
}
.floating_label4 {
position: absolute;
z-index: 200;
top: 65px;
**left: 170px;**
}
.floating_label5 {
position: absolute;
z-index: 200;
top: 65px;
**left: 190px;**
}
.floating_label6 {
position: absolute;
z-index: 200;
top: 65px;
**left: 210px;**
border: hidden;
}
}
</style>
Content:
<div style="position:relative;">
<img src="Images/PAXSummary.jpg" />
<asp:TextBox ID="TextBox1" runat="server" Text="1" style="height:25px; width:25px; vertical-align:central; text-align:center" CssClass="floating_label1" />
<asp:TextBox ID="TextBox2" runat="server" Text="2" style="height:25px; width:25px; vertical-align:central; text-align:center" CssClass="floating_label2" />
<asp:TextBox ID="TextBox3" runat="server" Text="3" style="height:25px; width:25px; vertical-align:central; text-align:center" CssClass="floating_label3" />
<asp:TextBox ID="TextBox4" runat="server" Text="4" style="height:25px; width:25px; vertical-align:central; text-align:center" CssClass="floating_label4" />
<asp:TextBox ID="TextBox5" runat="server" Text="5" style="height:25px; width:25px; vertical-align:central; text-align:center" CssClass="floating_label5" />
<asp:TextBox ID="TextBox6" runat="server" Text="6" style="height:25px; width:25px; vertical-align:central; text-align:center" CssClass="floating_label6" />
</div>
|
|
|
|
|
The answer was simple. The only thing that needed to be done was increase the values of each TextBox's CSS left and I was able to move the controls over to the desired location. I was only increasing the px value by 20 which was way to small of a value.
|
|
|
|
|
Now in my razor view i am want to see what is stored in my raw Model ? So tell me how could i show raw model in razor view ?
or want to see what is stored in first element of Model ?
i tried this way but getting error
@model JQDataTable.Controllers.TestData
@Html.Raw(Json.Encode(@Model))
OR
@Html.Raw(Model)
Getting error now for above code.
The model item passed into the dictionary is of type
'System.Collections.Generic.List`1[JQDataTable.Controllers.UserData]',
but this dictionary requires a model item of type 'JQDataTable.Controllers.TestData'.
please rectify my code as a result i will be able to print Model in razor page. thanks
|
|
|
|
|
It would just be
@Html.Raw(Json.Encode(Model))
However I don't see how that will produce the error you're getting. It looks like you are defining the model incorrectly. Rather than
@model JQDataTable.Controllers.TestData
you might need
@model List<JQDataTable.Controllers.UserData>
|
|
|
|
|
I got Error when i use Machine key in web config file in asp.Net Project.
|
|
|
|
|
|
Searched and worked hours trying to pull off/identify when a work/project is available on a web page. Below is the source of the page and my code. I can pull the tables, which are 7, but rows comes up as nothing. Want to pull when table id="workorders" and then = Project Name/work order
Thanks
Jim
Current Work Orders
No assigned work orders found.
-------if present, want to identity/capture this
My code
Get all tables in the document
Dim k As Integer
'
' Get all tables in the document
Dim tables As HtmlAgilityPack.HtmlNodeCollection = main.DocumentNode.SelectNodes("//table").innertext
' Iterate all rows in the first table
Dim rows As HtmlAgilityPack.HtmlNodeCollection = main.DocumentNode.SelectNodes("th")
' Iterate all rows in the first table
For k = 0 To rows.Count - 1
' Iterate all columns in this row
Dim cols As HtmlAgilityPack.HtmlNodeCollection = rows(k).SelectNodes("th")
If cols IsNot Nothing Then
For j As Integer = 0 To cols.Count - 1
' Get the value of the column and print it
Dim value As String = cols(j).InnerText
Console.WriteLine(value)
Next
End If
Next
Project Name/Work Order | Date | Time | Location | Tech | Pay Rate | Pay Type | Actions | | | | | | | |
|
|
|
|
|
Member 1753250 wrote:
Dim rows As HtmlAgilityPack.HtmlNodeCollection = main.DocumentNode.SelectNodes("th") You're iterating over all <th> nodes which are direct descendants of the document. There probably aren't any.
Instead, based on the comments, you probably want to iterate over the <tr> nodes which are direct descendants of the <table> :
Dim rows As HtmlAgilityPack.HtmlNodeCollection = tables(0).SelectNodes("tr") However, this will depend on the markup. The rows might not be direct descendants of the <table> ; they could be nested in one or more <thead> , <tbody> , or <tfoot> elements.
When you query for cells, you're also only looking for <th> elements. You're skipping ordinary <td> elements.
If you don't have to worry about nested tables, you could try:
Dim rows As HtmlAgilityPack.HtmlNodeCollection = main.DocumentNode.SelectNodes("//table[@id='workorders']//tr")
For i As Integer = 0 To rows.Count - 1
Dim cols As HtmlAgilityPack.HtmlNodeCollection = rows(i).SelectNodes("th|td")
...
Next
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|