Domanda

I have a project whereby a large number of technical specifications are currently 'published' as HTML files. The HTML files are not hosted on a web server, but zipped up and distributed to be access from a PC's local file system.

I am exploring the idea of creating a "publishing" system where the publisher could amend the content of the HTML files based on custom tags within the HTML itself. I suppose this would be similar to using PHP or ASP if it were server based.

So for example I might add

<Publisher action="___" params="________" />

The publisher would detect the presence of the "tag" do the required processing and then inject the necessary HTML into the files replacing the tag.

Does anyone know a way of achieving this using .NET based technology, or another way to achieve the same thing.

È stato utile?

Soluzione

OK, not sure if this is the most elegant solution, it works.

1) Based on Cannot delete directory with Directory.Delete(path, true) I clear down the target where the published "site" is intended to go.

2) I then copy all of the files using code based on the accepted solution to question Copy the entire contents of a directory in C#.

3) I intercept all of the "HTM" or "HTML" files and use a regexp to see if any "processing" is required. This is based of code from the site here http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.regex.replace(v=vs.71).aspx (shown below )

using System.Text.RegularExpressions;

class RegExSample 
{
   static string CapText(Match m) 
   {
     // Get the matched string.
     string x = m.ToString();
     // If the first char is lower case...
     if (char.IsLower(x[0])) 
     {
        // Capitalize it.
       return char.ToUpper(x[0]) + x.Substring(1, x.Length-1);
     }
     return x;
   }

   static void Main() 
   {
     string text = "four score and seven years ago";
     System.Console.WriteLine("text=[" + text + "]");
     string result = Regex.Replace(text, @"\w+",
        new MatchEvaluator(RegExSample.CapText));
     System.Console.WriteLine("result=[" + result + "]");
   }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top