How to Read all the Files from Server??? VERY URGENT [Resolved]

Posted by Laghaterohan under Regular Expressions on 12/14/2010 | Points: 10 | Views : 1655 | Status : [Member] | Replies : 2
Hello,

Please help me out its very urgent...
1. I have a upload control where in i browse multiple files and then click Upload.
2. After i click on Upload all my browsed files get stored at a server location (On Server).
3. After that i call my ReadFile method that reads the file on the server and inserts the data in the database 2005. Below is the code for the same:
 private void _ReadFile()
{
try
{

RBIFileReader reader = new RBIFileReader(FileUpload1.PostedFile.InputStream);
string[] data;
while ((data = reader.GetCSVLine()) != null)
{
ArrayList fileDetails = new ArrayList();
for (int i = 0; i < data.Length; i++)
{
string myString = data[i].ToString();
string s1= myString.Substring(0, 9);
fileDetails.Add(s1);
string s2= myString.Substring(9, 9);
fileDetails.Add(s2);
string s3= myString.Substring(18, 8);
fileDetails.Add(s3);
string s4= myString.Substring(26, 13);
fileDetails.Add(s4);
string s5= myString.Substring(39, 6);
fileDetails.Add(s5);
string s6= myString.Substring(45, 10);
fileDetails.Add(s6);
string s7= myString.Substring(55, 2);
fileDetails.Add(s7);
string s8= myString.Substring(57, 10);
fileDetails.Add(s8);

//// CODE TO INSERT THE DATA IN THE DATABASE

}

fileDetails = null;

}


}

catch
{
throw;
}
}


public class FileReader
{
private Stream objStream;
private StreamReader objReader;
//add name space System.IO.Stream
public FileReader (Stream filestream) : this(filestream,null) { }
public FileReader(Stream filestream, Encoding enc)
{
this.objStream = filestream;
//check the Pass Stream whether it is readable or not
if (!filestream.CanRead)
{
return;
}
objReader = (enc != null) ? new StreamReader(filestream, enc) : new StreamReader(filestream);
}

//parse the Line
public string[] GetCSVLine()
{
string data = objReader.ReadLine();
if (data == null) return null;
if (data.Length == 0) return new string[0];
//System.Collection.Generic
ArrayList result = new ArrayList();
//parsing CSV Data
ParseCSVData(result, data);
return (string[])result.ToArray(typeof(string));
}

private void ParseCSVData(ArrayList result, string data)
{
int position = -1;
while (position < data.Length)
result.Add(ParseCSVField(ref data, ref position));
}
}



MY PROBLEM IS THAT WHEN I BROWSE ONE FILE AT A TIME AND UPLOAD IT EVERYTHING WORKS PROPERLY..IE...IT IS UPLOAD AND THEN READ AND THEN THE DATA IN THE FILE IS INSERTED IN DATABASE...
HOWEVER, WHEN I BROWSE MULTIPLE FILES AND THEN UPLOAD THEM....THEN ONLY 1ST FILE''S DATA IS INSERTED IN THE DATABASE....!!! HOW WILL MY ALL FILES BE READ ONE BY ONE AND ACCORDINGLY DATA CAN BE INSERTED????

PLEASE HELP....


THANKS!!

Best Regards,
Rohan Laghate



Responses

Posted by: Laghaterohan on: 12/14/2010 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hey..i got it worked.....
sorry for trouble to you guys....i made a small silly mistake...:(



Thanks!!

Best Regards,
Rohan Laghate

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 12/14/2010 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Laghaterohan,

Could you please let everybody know what was that mistake so that all get benefited?

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Laghaterohan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response