Access to the path is denied

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();
}
}
}
}
}
 
L

Laurent Bugnion

Hi,

Mike said:
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.

The first explanation that comes to mind is that your ASPNET user has
write rights to the path you use in the second "procedure" (they're
actually methods), but not to the path you use in the first one.

ASP.NET, when it uses the file system, runs under the ASPNET user. Check
that the folder you want to write to allow the ASPNET user (on your
local machine) to do so.

HTH,
Laurent
 
G

Guest

Thanks for the reply, but I am writing both files to the same folder. When
you save a file, it always save on the client...correct?

You know, I learned the word procedure a long time ago and still have not
been able to stop saying it sometimes...thanks for the reminder :)
 
N

Norman Yuan

Mike Collins said:
Thanks for the reply, but I am writing both files to the same folder. When
you save a file, it always save on the client...correct?

Wrong. Your code is ASP.NET code, which runs on the server (IIS server) and
save file on the server side. Thus, you need to be clear which user account
is running your ASP.NET app (you, as the app developer, should know it,
shouldn't you?), and then give that account appropriate permission to access
file system on the server side.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top