|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Access to the path is deniedI 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(); } } } } } Hi,
Mike Collins wrote: > I am getting Access to the path is denied with the following procedure below. The first explanation that comes to mind is that your ASPNET user has > 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. 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 -- Laurent Bugnion, GalaSoft Software engineering: http://www.galasoft-LB.ch PhotoAlbum: http://www.galasoft-LB.ch/pictures Support children in Calcutta: http://www.calcutta-espoir.ch 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 :) Show quote "Laurent Bugnion" wrote: > Hi, > > Mike Collins wrote: > > 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 > -- > Laurent Bugnion, GalaSoft > Software engineering: http://www.galasoft-LB.ch > PhotoAlbum: http://www.galasoft-LB.ch/pictures > Support children in Calcutta: http://www.calcutta-espoir.ch > "Mike Collins" <MikeColl***@discussions.microsoft.com> wrote in message Wrong. Your code is ASP.NET code, which runs on the server (IIS server) and news:632566CA-E88D-43A5-BBA6-3E10A1CB24B2@microsoft.com... > 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? > 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. |
|||||||||||||||||||||||