This is my code :-
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
OleDbCommand command = new OleDbCommand(strSQL, connection);
try
{
string filename = "C:\\Users\\Pushkar\\Desktop\\Cp1dz_rpsmohangarden_" + DateTime.Now.ToString("yyyy-dd-MM-HH-mm-ss") + ".txt";
StreamWriter sw = new StreamWriter(filename);
connection.Open();
using (OleDbDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
sw.WriteLine("{0}, {1}, {2}, {3}", reader["AttendanceDate"].ToString(), reader["EmployeeId"].ToString(), reader["InTime"].ToString(), reader["OutTime"].ToString());
}
}
if (File.Exists(filename)
{
String uriString = @"http://192.168.4.99/mzc/admin/AttendanceController/upload_attendance_sheet/";
WebClient myWebClient = new WebClient();
string fileName = filename;
Console.WriteLine("Uploading {0} to {1} ...", fileName, uriString);
byte[] responseArray = myWebClient.UploadFile(uriString, fileName);
Console.WriteLine("\nResponse Received.The contents of the file uploaded are:\n{0}", System.Text.Encoding.ASCII.GetString(responseArray));
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
System.IO.IOException: The process cannot access the file 'C:\Users\Pushkar\Desktop\(generated txt file name)txt' because it is being used by another process.
Please Guide me
Pushkar PushpPosted Aug 27, 2018, 4:17 AM
Jaish MathewsPosted Aug 27, 2018, 4:01 AM
Sanwar RanwaPosted Aug 27, 2018, 2:07 AM
Pushkar PushpPosted Aug 27, 2018, 1:52 AM
Sanwar RanwaPosted Aug 27, 2018, 1:20 AM