Click here to Skip to main content
15,911,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a windows forms application which generates a string containing valid HTML. The string is eventually used in an eBay listing. The method I wrote just concatenates hardcoded strings and the incoming string variables. It works fine but is inflexible (what if I have two pictures?), inelegant, and ugly. There must be a better way to create HTML than just a couple of strings and a sledgehammer.

I've spent the afternoon Googling. I've looked at XDocument, HtmlDocument, DOM, StringBuilder, HtmlTextWriter, and probably more.

HtmlTextWriter seemed promising, but it is part of ASP.Net and I can't figure out how to get to it from a windows forms app. And, I suspect if it is that hard to get to it might not be the right solution. Should I just use StringBuilder?

Can anyone point me in the right direction? Thanks much.

C#
public static string MakeListingDescription(string title,string description,string pictureLocation1)
   {
       string doc = (
     "
    .
    .
    .
  a mess of html
    .
    .
"
 + description +
"
     .
     .
   a mess of html 
     .
     .
"
+ pictureLocation1 +
 "
      .
      .
   more html
      .
      .
"
 + title + 
"
      .
      .
 last of the html
      .
      .
" 
      return doc;
   }
Posted

I got an idea - seems silly but simple and may help. Why don't include your HTML file into your project, put a WebBrowser control on your windows form, and then open it? :-D
 
Share this answer
 
Comments
Dell.Simmons 3-Oct-10 22:04pm    
Not too silly, I hope - that's one of the solutions I thought about this afternoon. I'll think about it some more. Thanks. Other ideas anyone?
Hi,

what do you want exactly?
if you want to make a dynamic HTML page you can have a HTML file with the TOKENS as value. read the HTML file in you WinApp and replace all tokens with your data.
some thing like this:

MSIL
<HTML>
<body>
  <table>
  <tr>
   <td>FirstName:</td>
   <td>@TOKEN_FirstName@</td>
  </tr>
  <tr>
   <td>LastName:</td>
   <td>@Token_LastName@</td>
  </tr>
 </table>


Now you can replace the tokens in your WinApp and saveitin a new file.
(Replacing strings can take resources. so this way might have performance problem. even if you use StringBuilder)

hope this can help.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900