Html and xml file generator

Tamilmaran
Posted by Tamilmaran under C# category on | Views : 1686
Dear All


The Below code is console application code to generate xml and html file generator.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{


// Collect user input
string File1 = "";
string Count1 = "";
int Number1 = 0;
string[] Fields1;
string[] Types1;
while (File1 == String.Empty)
{
Console.Write("Please enter the file name:");
File1 = Console.ReadLine();
}
while (Count1 == String.Empty)
{
Console.Write("Please enter the number of fields:");
Count1 = Console.ReadLine();
try
{
Number1 = Convert.ToInt32(Count1);
}
catch
{
Count1 = "";
}
}
Fields1 = new string[Number1];
Types1 = new string[Number1];
for (int i = 0; i < Number1; i++)
{
int Field = i + 1;
Fields1[i] = "";
Types1[i] = "";
while (Fields1[i] == String.Empty)
{
Console.Write("Please enter the name for field " + Field.ToString() + " :");
Fields1[i] = Console.ReadLine();
if (Fields1[i].IndexOf(",") > 0)
{
string[] Field1 = new string[2];
char[] Char1 = { ',' };
Field1 = Fields1[i].Split(Char1);
Fields1[i] = Field1[0];
Types1[i] = Field1[1].ToUpper();
}
}
}
// Create XML file
StreamWriter StreamWriter1 = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + File1 + ".xml");
StreamWriter1.WriteLine("\r");
StreamWriter1.WriteLine("\r");
StreamWriter1.WriteLine("\r");
for (int x = 0; x < 2; x++)
{
StreamWriter1.WriteLine("<" + File1 + ">\r");
for (int a = 0; a < Number1; a++)
{
if (Types1[a].ToUpper() == "N")
{
StreamWriter1.WriteLine("<" + Fields1[a] + ">123.45\r");
}
else if (Types1[a].ToUpper() == "D")
{
StreamWriter1.WriteLine("<" + Fields1[a] + ">1/1/2005\r");
}
else if (Types1[a].ToUpper() == "B")
{
StreamWriter1.WriteLine("<" + Fields1[a] + ">true\r");
}
else
{
StreamWriter1.WriteLine("<" + Fields1[a] + ">String Data\r");
}
}
StreamWriter1.WriteLine("\r");
}
StreamWriter1.WriteLine("\r");
StreamWriter1.Close();


}
}
}

Comments or Responses

Login to post response