problems uploading a file... using the HtmlFileUpload control (<input type="file" ...>)

hey everyone, Im trying to run the following code...  

1    		public static void UploadItem(HttpPostedFile UploadedFile) {
2    
3    			int _fileLength = UploadedFile.ContentLength;
4    			byte[] _data = new byte[_fileLength];
5    
6    			UploadedFile.InputStream.Read(_data, 0, _fileLength);
7    
8    			string _filePath = "C:\\Development\\MBS Podcast\\MBSPodcast\\items";
9    			using (FileStream _fs = new FileStream(_filePath, FileMode.Create)) {
10   				try {
11   
12   					_fs.Write(_data, 0, _data.Length);
13   
14   				} catch (UnauthorizedAccessException unAuth) {
15   					throw new UnauthorizedAccessException(unAuth.Message);
16   				} catch (Exception ex) {
17   					throw new Exception(ex.Message);
18   				}
19   			
20   			}
21   
22   		}


however, im getting a UnauthorizedAccessException saying that access is denied for that directory, on the using (Filestream _fs...) Line (line 9).

 And when i copy the directory into run, minus the extra \, it shows the directory, so the directory is correctly located... 

I have added the MACHINE\ASPNET & MACHINE\IUSR_MACHINE for write access, I added my current user, as Windows.Identity.Name displays my user, still no go.
I even added the Everyone group will full control, and I am still getting this exception...what am I missing?  

Cheers, Justin

0
freefall
10/25/2007 12:44:13 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies
982 Views

Similar Articles

[PageSpeed] 20
Get it on Google Play
Get it on Apple App Store

The asp.net process runs under the ASPNET account under windows XP but uses the NETWORKSERVICE account when running under Windows Server.

Be sure to give read/write access to the NetworkService account.

 


Mike Banavige
~~~~~~~~~~~~

Need a site code sample in a different language? Try converting it with: http://converter.telerik.com/
0
mbanavige
10/25/2007 12:53:18 AM

Access denied message is because the folder already exists i'd expect. Check ur filepath, theres no filename at the end of it, just the directory (oops!).

Ur trying to create a file with the same name ("items") as a directory that already exists, therefore: Error 


-- Sam Critchley

"Wise man say 'forgiveness is divine, but never pay full price for late pizza." - TMNT

shivam.com.au
0
worldspawn
10/25/2007 1:10:01 AM

worldspawn[]:
Access denied message is because the folder already exists i'd expect. Check ur filepath, theres no filename at the end of it, just the directory (oops!).

Ur trying to create a file with the same name ("items") as a directory that already exists, therefore: Error 

Hi worldspawn[],  

I wasnt aware that it didnt just try and save the file to that directory...although, now that you mention that, all im telling it to do it write a byte array to the file...

 Thanks again for the replies...seems so simple, just never thought of it that way.

Cheers again!

0
freefall
10/25/2007 1:16:49 AM

Just another quick question,

What sort of permissions do I have to think about if this was to stored on a serpate server...IE, upload a file to network server '\\server\share\items'.

Do I just need to ensure that NetworkService has write access to this folder, or Do i need to setup a domain user that will be used for the asp.net service, and then add that user to have write properties on \\server\share ??

 Cheers again

0
freefall
10/25/2007 1:30:23 AM
Reply: