I Have written 2 methods in C# . one for getting records from excel sheet and one for inserting into excel sheet. both methods works fine when im running in my local system. but when i hosted it to appHarbor.com, getting records succeded but inserting failed.
here is the insert method
private bool AddBlessingToExcel(Blessing blessing)
{
try
{
string path = System.Web.HttpContext.Current.Server.MapPath("Data") + "/WeddingSheets.xls";
OleDbConnection myConnection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Extended Properties=Excel 8.0");
// always read from the sheet1.
OleDbCommand myCommand = new OleDbCommand("Insert into [Blessings$] (GuestName, GuestLocation, GuestMessage)" + " values ('" + blessing.GuestName + "', '" + blessing.GuestLocation + "', '" + blessing.GuestMessage + "')");
myConnection.Open();
myCommand.Connection = myConnection;
int val = myCommand.ExecuteNonQuery();
//Close the connection.
myConnection.Close();
return true;
}
catch(Exception ex)
{
//throw ex;
return false;
}
}
i dont know what the problem is exactly but my guess is its because of file permissions..can anyone please provide me a solution as soon as possible.
Inside the “Settings” page of the application, at the top of the page you should see an option named “Enable file system write access”, with a checkbox next to it.
That should give your app write access. However, I believe this gets reset every time you build, so you might have to enable it again after a new deployment.