|
This is the overall code for the pdf file.
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=a.pdf");
HttpContext.Current.Response.Charset = "";
HttpContext.Current.Response.ContentType = "application/pdf";
StringWriter stringwrite = new StringWriter();
HtmlTextWriter htmlwrite = new HtmlTextWriter(stringwrite);
repeater1.RenderControl(htmlwrite);
StringReader sr = new StringReader(stringwrite.ToString());
Document pdfDoc = new Document(PageSize.A4, 50f, 50f, 40f, 40f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.NewPage();
pdfDoc.Close();
suchita
|
|
|
|
|
By default the links and responses would stream in the same window. You can specify a target for the link but to respect the target as a new tab/window is up to the web browser, IMHO.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|
|
I am pulling data out of a SQL database into a GridView. The column names are dynamic so I never know what they will be (except the first column).
I would like to format the data (they are floating point numbers.)
I tried to use the RowDataBound event but it doesn't seem to do anything. Is there a way to format these numbers in a {F2} format? (I know that this code doesn't do it but I have tried a ton of things and none of them worked.)
This seems like an extremely clunky way to format the data. (We cannot format the data in SQL for other reasons.)
Thx
Mark Jackson
<code>
protected void gvFcstDmd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int i = 0;
DataRowView drv = e.Row.DataItem as DataRowView;
for (i = 1; i < drv.Row.ItemArray.Count(); i++) // start at one to not format the first column
{
drv[i] = Convert.ToString((Decimal)drv.Row.ItemArray[i]);
}
}
}
</code>
|
|
|
|
|
|
I looked at this before. We don't know the column names (they are dates) so I cannot access the columns using Cell["Label"]. I tried to use an index to loop thru the cells but that causes the thing to eliminate all but the first row.
I must say Microsoft's documentation for this stuff is appalling.
Thx
Mark Jackson
<code>
for (i = 1; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = Convert.ToDouble(e.Row.Cells[i]).ToString("F2");
}
</code>
|
|
|
|
|
Got it to work. Man this seems clunky tho
<pre>
protected void gvFcstDmd_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
int i;
TableCell c;
for (i = 1; i < e.Row.Cells.Count; i++)
{
c = e.Row.Cells[i];
c.HorizontalAlign = HorizontalAlign.Right;
Double d = Double.Parse(c.Text) * 1000;
c.Text = String.Format("{0,6:N0}",d);
}
}
}
</pre>
|
|
|
|
|
hi does anyone know the syntex of getting the list of files from a specific folder
when using asp.net 2005 c#?
|
|
|
|
|
Directory.GetFiles("*.*");
Help people,so poeple can help you.
|
|
|
|
|
You can use string array to retrieve the list of files from a perticular folder as :
String[] fileList=System.IO.Directory.GetFiles(@"C:\XYZ\");
|
|
|
|
|
hi i am currently using c# asp.net 2005.
i have a panel which is being populated by a unknown number of fileupload control.
so far it works fine, as i use a dropdownlist to populate the amount of fileupload control for the panel,
however when i click on the button to access the panel's control the panel always reset.
i read somewhere that this is cause by the post back of the button hence the controls in the button act as if they never existed.
does anyone have any solution for this they can recommend for this please?
|
|
|
|
|
Hello,
I recommand to use the Callback and not postback.
For more infotmations you can check this topic : Callback WebControls[^]
I hope that will help you.
Good luck.
|
|
|
|
|
Hi Experts,
The below given is the Regex pattern for validating e-mail. I have to do it in 2 ways one is through UI and another one is through excel import. In UI i am using the same Regex pattern as given below using regularexpressionvalidator. It is correctly validation "sam@ple@code.com" and "'sam@ple@code.com'" - @@ and '' are correctly restricted in UI but when i use the same in code it is not validationg the given 2 email ids and allowing me to insert. how to avoid double @ and single quoted. i want the Regex pattern. can anyone help me in this?
UI- working fine
===
ValidationExpression="\w+([-+.']\w+([-]*))*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
Inside code - not working for double @ and '
============
Regex patternMatch = new Regex("\\w+([-+.']\\w+([-]*))*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");//("(\\d|-| | )*");
|
|
|
|
|
I use this : www.regxlib.com [^], otherwise I'll whittle my life away creating the "perfect" regex
|
|
|
|
|
Displaying the image from the Sql
Hi,
I am trying to display image on the page stored in the SQL DB.
Image is store in the <BinaryData> format in the DB. I am display in the DataGrid its working fine, problem with page.
SqlCommand Cmd = new SqlCommand(Query, myconnection);
SqlDataReader dr = Cmd.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
lblProdName.Text = Product;
lblProdDesc.Text = dr[0].ToString();
lblPrice.Text = dr[3].ToString();
byte[] Photo = (byte[])dr[5];
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(Photo, 0, Photo.Length);
}
dr.Close();
only image is displayed on the page without any other content ,
if I comment lines
All the contents are displayed except the image.
what is the proper way to display the image on the page using SQL ??
Please help me with this.
Thanking you,
Naveen.
|
|
|
|
|
try this
Response.ContentType = "image/jpeg" ;<br />
Response.BinaryWrite(dr["ImageField"])) ;
I Love T-SQL
"Don't torture yourself,let the life to do it for you."
If my post helps you kindly save my time by voting my post.
www.cacttus.com
|
|
|
|
|
Basically, you want to push a complete web page to a browser, but browsers are designed to pull pages.
I don't think you can send two streams like that for one display page (text + image).
However, if you programmatically create a ".mht" page, you cvould probably do what you're tryign to do. Maybe something in this article will give you an idea: Convert HTML to MHTML using ASP.NET[^]
|
|
|
|
|
GenJerDan wrote: you want to push a complete web page to a browser
What? No, the page is being rendered in response to a request. It's not like the web server is randomly connecting to some machine and trying to send content.
GenJerDan wrote: I don't think you can send two streams like that
There is only one stream. The images is being placed within that stream.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Mark Nischalke wrote: What? No, the page is being rendered in response to a request. It's not like the
web server is randomly connecting to some machine and trying to send
content.
Yes, but, basically, a browser requests something and the server delivers it in the stream, i.e. a pull, not a push. Then the browser "looks" at what it got and says to itself Ah-hah! I need to get the image for this. I better request another stream for it. It doesn't all come in one clump. Trying to send two streams when the broweser is only capable of requesting one at a time is not going to work.
Mark Nischalke wrote: There is only one stream. The images is being placed within that stream.
Nope. There needs to be multiple responses, one for each discrete item. Or there needs to be something on the browser itself that can take a multiplexed stream and demux it. An ActiveX control could do that....but there are too many problems there, the least of which is convincing the user to load yet another plugin. But the MHTML process is already built-in, which is why I suggested it. The only difficulty is in creating the MHTML object in your server code.
You can downvote me all you want, but it won't change the way browsers work.
|
|
|
|
|
GenJerDan wrote: There needs to be multiple responses, one for each discrete item.
Correct, one at a time.
What the OP was asking to is insert the image into the ONE stream along with the text, all of which which would be streamed to the requesting browser as one chunk of binary data. It is possible and is done quite frequently.
GenJerDan wrote: it won't change the way browsers work.
No but I think you need to change your understanding how things work. The down vote was justified because you are incorrect in your views and what you are suggesting is just plain wrong.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Oh, really? So what Content-Type type is text with embedded image that a browser can handle, other than as an email client? Other than the MHTML, of course.
Or should we all start worrying every web page out there being able to piggyback whatever they want in a content stream?
|
|
|
|
|
OK - what you're doing here is explicitly telling the browser that what's coming is an image in jpeg format (Response.ContentType), and that the content itself is the bytestream (Response.OutputStream.Write).
With those lines in place, you're NOT rendering anything else to the browser - just the image.
The default Response.ContentType is (IIRC) text/html - which is effectively a webpage, so with the lines commented, you're basically saying "do the normal thing", and not writing anything explicitly.
To render the image with the text, you need to set the Source of an Image control that's part of the page.
Something similar to the following...
byte[] imageData = (byte[])dr[5];
MemoryStream memStream = new MemoryStream(imageData);
image = Image.FromStream(memStream);
Which incidentally is pretty much ripped off wholesale from the top link in Google[^]
C# has already designed away most of the tedium of C++.
|
|
|
|
|
Hi,
I don't know if you have sorted this out but the last person who commented got it right though unclear.
What he/she meant is that have an already existing img/image on you page that it's src comes from another page like so:
<img id="theImageFromSQL" runat="server" alt="theImageFromSQL" src="ImagesPage.aspx?id=someId" />
//when a browser loads the image it will call ImagesPage.aspx and this page will write back JUST an image which is what you want (i guess)
You can leave the other controls on the 'main' page which could be Home.aspx/Default.aspx and ofcourse your img/image will be in this same main page.
shout if u need more help
Morgs
|
|
|
|
|
Hi,
im not able to find ActionLink<> in vs 2010 ..please help me..
what is the workaround for <%=Html.ActionLink<HomeController>(x => x.Index(),"Home")%>as the above line throws..error..bcos Strongly typed ActionLink is not present
|
|
|
|
|
|
I am trying to find the url of webservice from a page inside a subdirectory in my website. I am using a separate script file referenced in my page. This does not work in the script file
var pgUrl='<%= ResolveUrl("~/assets/WebServices/Admin/UsrRoleService.asmx") %>';
How do I find the application url in the script file ?
|
|
|
|