How can we read a columnised text data in ASP.Net C#?
Columnised means my data is stored in a text file and I
have numeric data or string data in this file. For ex. If I
am searching for the data of gender and I know that gender
data is stored at column 32 in text file. How can I get
this data in ASP.Net page. Thanks for help in advance.
Answer Posted / praveen kumar
string OpenPath, contents;
int tabSize = 4;
string[] arInfo;
string line;
DataTable table = CreateTable();
DataRow row;
try
{
OpenPath = Server.MapPath(".") + @"\My
File.log";
string FILENAME = OpenPath;
//Get a StreamReader class that can be used
to read the file
StreamReader objStreamReader;
objStreamReader = File.OpenText(FILENAME);
while ((line = objStreamReader.ReadLine())
!= null)
{
contents =
line.Replace(("").PadRight(tabSize, ' '), "\t");
// define which character is seperating
fields
char[] textdelimiter = { ']' };
arInfo = contents.Split(textdelimiter);
for (int i = 0; i <= arInfo.Length; i++)
{
row = table.NewRow();
if (i < arInfo.Length)
row["Type"] =
arInfo[i].ToString().Replace("[", " ");
if (i + 1 < arInfo.Length)
row["Source"] = arInfo[i +
1].ToString().Replace("[", " ");
if (i + 2 < arInfo.Length)
row["Time"] = arInfo[i +
2].ToString().Substring(1);
if (i + 3 < arInfo.Length)
{
row["Description"] = arInfo[i +
3].ToString().Replace("[", " ");
table.Rows.Add(row);
}
i = i + 2;
}
}
Is This Answer Correct ? | 1 Yes | 1 No |
Post New Answer View All Answers
What are the advantages and disadvantages of Using Cookies?
How can you identify that the page is post back?
Explain about asp.net 2.0 themes?
Demonstrate Render and PreRender?
what are the web form events available in asp.net?
Explain difference between dataset and recordset?
What is a server cookie?
What is a 307 redirect?
Explain repository pattern in asp.net mvc? : asp.net mvc
Is asp.net different from asp? If yes, explain how?
Explain how dot net compiled code will become platform independent?
How can we apply themes to an asp.net application?
If you want to write your own dot net language, what steps you will you take care?
What is session state server?
1.What r collections? 2.What is .pdb file? 3.Is it possible to provide access to users in master page? 4.What is dirty n Phantom Read(SQL)? 5.What r different isolation levels(SQL)? 6.How to set authentication mode in web.config file?