G
Guest
I am getting Access to the path is denied with the following procedure below.
I know I'm showing my ignorance here, but in a different procedure, I am
writing an xml file to disk using a DataSet object: ds.WriteXml(@exportPath,
XmlWriteMode.WriteSchema);. What is the difference in using a FileStream
object and can someone explain to me if I can do this as I do not know which
client computers will be calling the page, so I will not be able to add
permissions to each one. Thank you.
public static void Export (string recordID)
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString = ConfigurationSettings.AppSettings
"DatabaseConnectionString"] + databaseName;
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand readerCommand = new SqlCommand("GetAttachmentIDs", conn);
readerCommand.CommandType = CommandType.StoredProcedure;
SqlParameter readerParam;
readerParam = readerCommand.Parameters.Add("@recordID",
SqlDbType.UniqueIdentifier);
readerParam.Value = new Guid(recordID);
conn.Open();
using (SqlDataReader reader = readerCommand.ExecuteReader())
{
while (reader.Read())
{
using (SqlConnection conn2 = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand("GetAttachment", conn2);
command.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = command.Parameters.Add("@attachmentID",
SqlDbType.UniqueIdentifier);
param.Value = new Guid(reader["AttachmentID"].ToString());
conn2.Open();
byte[] barrImg =(byte[])command.ExecuteScalar();
FileStream fs = new FileStream(@"D:\" + recordID + "." +
reader["FileExtension"].ToString(), FileMode.CreateNew, FileAccess.Write);
fs.Write(barrImg, 0, barrImg.Length);
fs.Flush();
fs.Close();
}
}
}
}
}
I know I'm showing my ignorance here, but in a different procedure, I am
writing an xml file to disk using a DataSet object: ds.WriteXml(@exportPath,
XmlWriteMode.WriteSchema);. What is the difference in using a FileStream
object and can someone explain to me if I can do this as I do not know which
client computers will be calling the page, so I will not be able to add
permissions to each one. Thank you.
public static void Export (string recordID)
{
string databaseName =
HttpContext.Current.Session["DatabaseName"].ToString();
string connectionString = ConfigurationSettings.AppSettings
"DatabaseConnectionString"] + databaseName;
using (SqlConnection conn = new SqlConnection(connectionString))
{
SqlCommand readerCommand = new SqlCommand("GetAttachmentIDs", conn);
readerCommand.CommandType = CommandType.StoredProcedure;
SqlParameter readerParam;
readerParam = readerCommand.Parameters.Add("@recordID",
SqlDbType.UniqueIdentifier);
readerParam.Value = new Guid(recordID);
conn.Open();
using (SqlDataReader reader = readerCommand.ExecuteReader())
{
while (reader.Read())
{
using (SqlConnection conn2 = new SqlConnection(connectionString))
{
SqlCommand command = new SqlCommand("GetAttachment", conn2);
command.CommandType = CommandType.StoredProcedure;
SqlParameter param;
param = command.Parameters.Add("@attachmentID",
SqlDbType.UniqueIdentifier);
param.Value = new Guid(reader["AttachmentID"].ToString());
conn2.Open();
byte[] barrImg =(byte[])command.ExecuteScalar();
FileStream fs = new FileStream(@"D:\" + recordID + "." +
reader["FileExtension"].ToString(), FileMode.CreateNew, FileAccess.Write);
fs.Write(barrImg, 0, barrImg.Length);
fs.Flush();
fs.Close();
}
}
}
}
}