Last post Mar 08, 2011 02:11 AM by Shengqing Yang - MSFT
Mar 02, 2011 09:30 AM|paraskumar0730|LINK
Is their any solution in which i can fetch only few part of the text file data into the variable instead of reading all the content and saving into the
variable because my text file is of 7 mb and its impossible to store all the 7 mb data into a variable.
any help would be appreciated.
Mar 02, 2011 10:34 AM|ddelella|LINK
You will still need to go through the document to get out the lines you need. The streams only read one direction in a linear fashion. Do you know what you want to get out the file? Why do you only need part of it?
Mar 03, 2011 12:10 AM|sirdneo|LINK
Here is a sample which will guide you that how to read data from a file:-
Mar 03, 2011 02:07 AM|KumarHarsh|LINK
Yes streamRead is the solution.
any problem ask.
Mar 03, 2011 03:48 AM|paraskumar0730|LINK
Thanks for the suggestion. I agree to your point, my problem is that if i have to read the full document then it goes into hanging position because its taking very long time to fetch. I want to search a particular line in the text file. if i found that i
will come out of the filestream reader. Plz suggest.
Mar 03, 2011 06:24 AM|KumarHarsh|LINK
stringbuilder sb=reader.ReadtoEnd();//don't read line by line.
string strToSearch="vbnvbn bvnbvn";
search this strSearch in sb.
Will it take long time ?
Use indexing Search.
Suppose there is folder called. "txtfilecontent" it contain all text file.it may contain one file or several file.
Implement indexing search for this folder only.If your folder contain only neccessary file then it won't take much time.
now in web application,search textbox,you enter string to search click button.
it will search for you and display in web page.
No idea which one is faster.
Mar 03, 2011 09:51 AM|sirdneo|LINK
Can you share samples what you want to search in text file and what are the contents of of text file so it will be easier to answer solution for your problem.
Mar 03, 2011 11:32 AM|ddelella|LINK
This should work. I would not use StringBuilder for this because it does not have any great searching functions. StringBuilder works great for dynamically compiling strings.
Private Function IsStringFound(ByVal FilePath As String, ByVal StringToFind As String) As Boolean
Using MyReader As New StreamReader(FilePath)
Dim Text As String = MyReader.ToString
If Text.Contains(StringToFind) Then
Mar 03, 2011 12:26 PM|reneesherry|LINK
I would not suggest reading text files from your site. Always use databases, reading text files causes all sorts of issues, associated with file locking.
We see these issues with our clients all the time.
Mar 08, 2011 02:11 AM|Shengqing Yang - MSFT|LINK
Maybe you can use this command to search for your text:
Call the command from .NET code and you can get your result efficiently.