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 is OSI layer? Explain different layers.
What is the purpose of using MVC programming pattern in ASP.NET?
Describe the differences between the lifecycles of Windows services and Standard EXE?
What are the navigation ways between pages available in ASP.NET?
What is difference between abstract class and an interface?
What is the difference between the get method () and post method ()?
What is the use of web.config and machine.config files?
Can we override the enablepartialrendering property of the scriptmanager class?
What are the modes of updation in an updatepanel? What are triggers of an updatepanel?
If you want to bind the columns manually within the asp:datagrid tags what kind of tags you have to add.
What is a postback in asp net?
Which .NET framework supports Web API?
What are the advantages of using session?
How do you secure your configuration files to be accessed remotely by unauthorized users?
I have created a configuration setting in my web.config and have kept it at the root level. How do I prevent it from being overridden by another web.config that appears lower in the hierarchy?