1

I'm trying to use HtmlTextWriter to create a html page which is all working fine until I try to create images into a folder that contains spaces in its file path

C:\Documents and Settings....

What seems to be happening is

m_htmlWriter.AddAttribute(HtmlTextWriterAttribute.Src, imageName);

is converting spaces into %20 which as a result, the file path for the source becomes invalid and results in my webbrowser and installed internet browsers not being able to display said images, and instead displaying the broken image icon/image..

I've tried multiple different things to get this to work including

Uri.UnescapeDataString, including an @ symbol infront of the imageName

I've also found that if i copy the link from the page source (C:\Documents%20and%20Settings\... then windows is unable to find the file(expected this)

I'm unable to use HtmlAgilityPack due to restrictions I am under.. Anyone have any ideas?

Sayse
  • 42,633
  • 14
  • 77
  • 146

1 Answers1

0

Just add a boolean parameter to tell the HtmlTextWriter class that you don't want it encoded: -

m_htmlWriter.AddAttribute(HtmlTextWriterAttribute.Src, imageName, false);

There are two similar methods available:

AddAttribute(HtmlTextWriterAttribute, String)
AddAttribute(HtmlTextWriterAttribute, String, Boolean)

Using the second one should fix the problem.

MIWMIB
  • 1,407
  • 1
  • 14
  • 24
  • According to the documentation its false by default, I'm pretty sure I tried this.. In the end I just hardcoded html image tags – Sayse Jul 03 '13 at 16:40