473,326 Members | 2,182 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Ellegant inserting js code in dynamically created file

Hi,
I need to create html file dynamically from C# code. I need to place
there some javascript code. This js code I'm keeping in fukctions.js
file. Now, I'm generating HTML code, for example:

string htmlContent ="<html><body></body></html>";
......
saveHtmlFile(htmlContent);
and I would like to do something like:
htmlContent+=jsCodeFromFile();before calling saveHtmlFile()

Of course I need to keep this js code in my html file, not in separate
file.
Does anyone know some good solution?

Oct 12 '06 #1
2 1176
Good day,

For starters, I'd highly recommend using the HtmlTextWriter to build
some html dynamically, or at least the StringBuilder class.

Once you get that organized, it's easy to extract the contents of a
file:

[using system.io]

FileStream jsFile = new FileStream(Server.MapPath("functions.js"),
FileMode.Open);

byte[] jsBytes = new byte[jsFile.Length);

//depending on how you're writing to your file, you can either write
some bytes to it orconvert your bytes into a string using this..

string jsFileContents =
System.Text.UTF8Encoding.UTF8.GetString(jsBytes);

//do whatever you need to here...
jsFile.Close();

Hope this helps...

-Brenton

ma***@o2.pl wrote:
Hi,
I need to create html file dynamically from C# code. I need to place
there some javascript code. This js code I'm keeping in fukctions.js
file. Now, I'm generating HTML code, for example:

string htmlContent ="<html><body></body></html>";
.....
saveHtmlFile(htmlContent);
and I would like to do something like:
htmlContent+=jsCodeFromFile();before calling saveHtmlFile()

Of course I need to keep this js code in my html file, not in separate
file.
Does anyone know some good solution?
Oct 12 '06 #2
Thanks, that might to be the only one logic solution. Anyway it looks
better then writing

jsString+="<script>"
jsString+="......"
jsString+="</script>"

Thanks,
Marcin

Oct 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Little PussyCat | last post by:
Hello, I have had a request, one of our tables is used as a report and I have been asked that all fieldnames for months have dashes in them, like Jan-05 instead of Jan05 and so on... Now what...
2
by: a | last post by:
NEW Post Here's my best guess at how to insert this dataset.... the code runs, but no new records are added to the sql table. I've read and split a delimited text file into a dataset. It...
1
by: Russ | last post by:
I've been trying to get my head around this for 3 days now and it seems like everything I try does not work for one reason or another. I built a test page using the TabStrip and MultiPage controls....
1
by: Jeffrey Todd | last post by:
I have successfully created functionality that mostly models what I'm trying to do - which is dynamically insert controls into a user control (ascx), and insert validation controls, also...
2
by: gruvin | last post by:
Hi. I need to insert an image element into text in an iframe in design mode. That part I can do: var sel = oEditor.eFrameDoc.selection; var range = sel.createRange(); range.pasteHTML('<img...
5
by: arnabit | last post by:
I have created a dropdown ,which is inside a panel and the panel is inside a place holder . the panel and the dropdown is created dynamically. I do have a button when the button is clicked i am...
3
by: kj | last post by:
I've tried a bazillion ways to code dynamically generated methods, to no avail. The following snippet is a very simplified (and artificial) demo of the problem I'm running into, featuring my...
20
by: dav3 | last post by:
Alright folks I am in need of a lil guidance/assistance here. I have a program which reads in a txt file. This txt file contains lines of the form January 3, 2007, 85.8 Now each line of the txt...
1
by: codexxx | last post by:
Hi All, We have setup an Amazon webstore and we anticipate uploading 10,000+ products, and therefore to avoid unnecessary manual labor we wish to automate as much of the process of adding and...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.