2

My C# program uses a web browser control and I programmatically set its html property by laoding it from a html string variable. This almost works well ,but I noticed it lost the reference to the css file. I think a simplest solution is to make the path of the css file absolute,but I want it remains relative to the C# executable.So let me ask how to let the html reference to the css file in such a context.

Thank you in advance.

Edit: I am sorry . My c# application is a desktop one ,although it uses a web browser control. Edit: Let me put some code. I first load the document from an html file then store it in a variable then for the 2nd time or later I load the document from the variable.

  //first load
  web_browser_control.Url = new Uri( dir + @"\HTML\default1.html" );

  void wB2_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
  {   html_string = web_browser_control.DocumentText; }

  //second load or later
  web_browser_control.DocumentText = html_string;
6
  • Why does it lose a reference to the css file -- can you explain? Commented Apr 2, 2012 at 11:06
  • Why don't you set the css via stylesheet or via style tag in your aspx page? Commented Apr 2, 2012 at 11:12
  • @George I think as the html string loaded into the web control has no its address in the local file system. Commented Apr 2, 2012 at 11:19
  • @RaghavKhunger Khunger I am sorry I did not say that my C# application is a desktop one ,but not for web. Commented Apr 2, 2012 at 11:22
  • again i'd ask what control you are using is this a prebuilt control from a vendor or something you have written Commented Apr 2, 2012 at 12:53

2 Answers 2

2

You need to have a look at what path it THINKS its resolving, it would be best if you could please include some code, chances are its not resolving to where you think it is as its executing out of the bin directory (is your path correct relative to the path of the executable and the html),

For example is the html its looking at still where you think it is or is it now in a different directory so the relative paths are now obsolete ?

More code would be good and an indication of the control you are using.

Sign up to request clarification or add additional context in comments.

Comments

2

Seems you can change property of css file to be "content" and make property "copy to output directory" - "always", so the wep app dll will be in the same directory with css file. Or you can use MapPath method.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.