By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,121 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Problem creating folder in C# Asp.Net

P: n/a
Zeb
Hi all

I've developed a shopping cart in C# and to allow moderators to upload
product images, news images and downloadable PDFs, the app creates a
folder for each product. I start out with the following empty folders:

/img/products/
/img/news/
/pdf/

When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.

This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up with
the following exception:

"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"

I'm using DirectoryInfo.Create to create the new folders.

Interestingly, I wrote a quick ASP3 script that creates folders in the
root of the site and this works fine.

I did read a post yesterday that suggests the aspnet client needs read
access to the root of the physical drive (in this case, D:) to be able
to create folders and that most shared servers won't allow this.

Is this really the case, and if it is, what's the best solution? There
must be a way to dynamically create folders on shared hosting
servers ....

Many thanks for any helpful suggestions!

Feb 1 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
JE
You have to configure the security on the folder give the ASP.Net
account the necessary permissions.
Zeb wrote:
Hi all

I've developed a shopping cart in C# and to allow moderators to upload
product images, news images and downloadable PDFs, the app creates a
folder for each product. I start out with the following empty folders:

/img/products/
/img/news/
/pdf/

When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.

This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up with
the following exception:

"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"

I'm using DirectoryInfo.Create to create the new folders.

Interestingly, I wrote a quick ASP3 script that creates folders in the
root of the site and this works fine.

I did read a post yesterday that suggests the aspnet client needs read
access to the root of the physical drive (in this case, D:) to be able
to create folders and that most shared servers won't allow this.

Is this really the case, and if it is, what's the best solution? There
must be a way to dynamically create folders on shared hosting
servers ....

Many thanks for any helpful suggestions!
Feb 1 '07 #2

P: n/a
Zeb
On 1 Feb, 11:22, JE <jgegroups.s...@gmail.nospam.comwrote:
You have to configure the security on the folder give the ASP.Net
account the necessary permissions.

Zeb wrote:
Hi all
I've developed a shopping cart in C# and to allow moderators to upload
product images, news images and downloadable PDFs, the app creates a
folder for each product. I start out with the following empty folders:
/img/products/
/img/news/
/pdf/
When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.
This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up with
the following exception:
"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"
I'm using DirectoryInfo.Create to create the new folders.
Interestingly, I wrote a quick ASP3 script that creates folders in the
root of the site and this works fine.
I did read a post yesterday that suggests the aspnet client needs read
access to the root of the physical drive (in this case, D:) to be able
to create folders and that most shared servers won't allow this.
Is this really the case, and if it is, what's the best solution? There
must be a way to dynamically create folders on shared hosting
servers ....
Many thanks for any helpful suggestions!- Hide quoted text -

- Show quoted text -
What are the necessary permissions though? The ISP seem to think that
the permissions on that folder will allow the creation of new folders
by the aspnet account ..

Feb 1 '07 #3

P: n/a
The ISP has locked down ASP.NET using Partial Trust (the <trustelement
in web.config) - i don't know exactly which permisssions he chose - but by
default you will only have filesystem access to your web directory from ASP.NET.

Besides that - you cannot create subdirectory in the asp.net web directory
- every directory creation will result in an AppDomain recycly and you will
lose stuff like session/cache etc..

I guess you will have to talk to the ISP to change permissions (he most prolly
won't do that) - maybe you have to get a dedicated server.

-----
Dominick Baier (http://www.leastprivilege.com)
Hi all

I've developed a shopping cart in C# and to allow moderators to upload
product images, news images and downloadable PDFs, the app creates a
folder for each product. I start out with the following empty folders:

/img/products/
/img/news/
/pdf/
When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.

This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up with
the following exception:

"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"

I'm using DirectoryInfo.Create to create the new folders.

Interestingly, I wrote a quick ASP3 script that creates folders in the
root of the site and this works fine.

I did read a post yesterday that suggests the aspnet client needs read
access to the root of the physical drive (in this case, D:) to be able
to create folders and that most shared servers won't allow this.

Is this really the case, and if it is, what's the best solution? There
must be a way to dynamically create folders on shared hosting
servers ....
Many thanks for any helpful suggestions!

Feb 1 '07 #4

P: n/a
Zeb
On 1 Feb, 12:59, Dominick Baier
<dbaier@pleasepleasenospam_leastprivilege.comwrote :
The ISP has locked down ASP.NET using Partial Trust (the <trustelement
in web.config) - i don't know exactly which permisssions he chose - but by
default you will only have filesystem access to your web directory from ASP.NET.

Besides that - you cannot create subdirectory in the asp.net web directory
- every directory creation will result in an AppDomain recycly and you will
lose stuff like session/cache etc..

I guess you will have to talk to the ISP to change permissions (he most prolly
won't do that) - maybe you have to get a dedicated server.

-----
Dominick Baier (http://www.leastprivilege.com)
Hi all
I've developed a shopping cart in C# and to allow moderators to upload
product images, news images and downloadable PDFs, the app creates a
folder for each product. I start out with the following empty folders:
/img/products/
/img/news/
/pdf/
When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.
This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up with
the following exception:
"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"
I'm using DirectoryInfo.Create to create the new folders.
Interestingly, I wrote a quick ASP3 script that creates folders in the
root of the site and this works fine.
I did read a post yesterday that suggests the aspnet client needs read
access to the root of the physical drive (in this case, D:) to be able
to create folders and that most shared servers won't allow this.
Is this really the case, and if it is, what's the best solution? There
must be a way to dynamically create folders on shared hosting
servers ....
Many thanks for any helpful suggestions!- Hide quoted text -

- Show quoted text -
Damn. Thanks for the info Dominick... most helpful as always.

Do you know of any other solutions? The only one I can think of is to
store the images and pdfs as blobs in the database. I was reluctant to
do this, but it seems I may not have a choice.

I find it strange that I can't create a subdirectory though. I've
developed a site for a dedicated server in the past where users could
upload images in the same way, and sub directories were created ...
and session details were not lost. There must be plenty of sites out
there on shared hosting that do the same...

I guess I'll just have to continue testing / talking to the ISP, and
if all else fails I'll just have to use blobs.

Feb 1 '07 #5

P: n/a
The subdir behavior has changed in 2.0 - you can easily try that -

simply create a folder and watch the appdomain shut down...
-----
Dominick Baier (http://www.leastprivilege.com)
On 1 Feb, 12:59, Dominick Baier
<dbaier@pleasepleasenospam_leastprivilege.comwrote :
>The ISP has locked down ASP.NET using Partial Trust (the <trust>
element in web.config) - i don't know exactly which permisssions he
chose - but by default you will only have filesystem access to your
web directory from ASP.NET.

Besides that - you cannot create subdirectory in the asp.net web
directory - every directory creation will result in an AppDomain
recycly and you will lose stuff like session/cache etc..

I guess you will have to talk to the ISP to change permissions (he
most prolly won't do that) - maybe you have to get a dedicated
server.

-----
Dominick Baier (http://www.leastprivilege.com)
>>Hi all

I've developed a shopping cart in C# and to allow moderators to
upload product images, news images and downloadable PDFs, the app
creates a folder for each product. I start out with the following
empty folders:

/img/products/
/img/news/
/pdf/
When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.
This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up
with the following exception:

"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"

I'm using DirectoryInfo.Create to create the new folders.

Interestingly, I wrote a quick ASP3 script that creates folders in
the root of the site and this works fine.

I did read a post yesterday that suggests the aspnet client needs
read access to the root of the physical drive (in this case, D:) to
be able to create folders and that most shared servers won't allow
this.

Is this really the case, and if it is, what's the best solution?
There
must be a way to dynamically create folders on shared hosting
servers ....
Many thanks for any helpful suggestions!- Hide quoted text -
- Show quoted text -
Damn. Thanks for the info Dominick... most helpful as always.

Do you know of any other solutions? The only one I can think of is to
store the images and pdfs as blobs in the database. I was reluctant to
do this, but it seems I may not have a choice.

I find it strange that I can't create a subdirectory though. I've
developed a site for a dedicated server in the past where users could
upload images in the same way, and sub directories were created ...
and session details were not lost. There must be plenty of sites out
there on shared hosting that do the same...

I guess I'll just have to continue testing / talking to the ISP, and
if all else fails I'll just have to use blobs.

Feb 1 '07 #6

P: n/a
Zeb
On 1 Feb, 14:25, Dominick Baier
<dbaier@pleasepleasenospam_leastprivilege.comwrote :
The subdir behavior has changed in 2.0 - you can easily try that -

simply create a folder and watch the appdomain shut down...

-----
Dominick Baier (http://www.leastprivilege.com)
On 1 Feb, 12:59, Dominick Baier
<dbaier@pleasepleasenospam_leastprivilege.comwrote :
The ISP has locked down ASP.NET using Partial Trust (the <trust>
element in web.config) - i don't know exactly which permisssions he
chose - but by default you will only have filesystem access to your
web directory from ASP.NET.
Besides that - you cannot create subdirectory in the asp.net web
directory - every directory creation will result in an AppDomain
recycly and you will lose stuff like session/cache etc..
I guess you will have to talk to the ISP to change permissions (he
most prolly won't do that) - maybe you have to get a dedicated
server.
-----
Dominick Baier (http://www.leastprivilege.com)
Hi all
>I've developed a shopping cart in C# and to allow moderators to
upload product images, news images and downloadable PDFs, the app
creates a folder for each product. I start out with the following
empty folders:
>/img/products/
/img/news/
/pdf/
When a new item is uploaded, the app first creates a folder in the
appropriate place and the folder is named using the product or news
ID. The uploaded files can also be deleted later if necessary.
This works fine locally, but won't work on the remote shared server.
When I try to create the folder on the uploaded website I end up
with the following exception:
>"Request for the permission of type
'System.Security.Permissions.FileIOPermission, mscorlib,
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
failed"
>I'm using DirectoryInfo.Create to create the new folders.
>Interestingly, I wrote a quick ASP3 script that creates folders in
the root of the site and this works fine.
>I did read a post yesterday that suggests the aspnet client needs
read access to the root of the physical drive (in this case, D:) to
be able to create folders and that most shared servers won't allow
this.
>Is this really the case, and if it is, what's the best solution?
There
must be a way to dynamically create folders on shared hosting
servers ....
Many thanks for any helpful suggestions!- Hide quoted text -
- Show quoted text -
Damn. Thanks for the info Dominick... most helpful as always.
Do you know of any other solutions? The only one I can think of is to
store the images and pdfs as blobs in the database. I was reluctant to
do this, but it seems I may not have a choice.
I find it strange that I can't create a subdirectory though. I've
developed a site for a dedicated server in the past where users could
upload images in the same way, and sub directories were created ...
and session details were not lost. There must be plenty of sites out
there on shared hosting that do the same...
I guess I'll just have to continue testing / talking to the ISP, and
if all else fails I'll just have to use blobs.- Hide quoted text -

- Show quoted text -
That would explain it - the site I mentioned was .net 1.1.

How rubbish. I guess they have their reasons though, so I'll just have
to live with it!

Would you recommend any approach in particular? Are blobs the way to
go?

Feb 1 '07 #7

P: n/a
Zeb
The answer!!!

Here's some lateral thinking for you. Rather than create new folders,
I'll simply take the ProductID and file name, hash them into a unique
filename and upload them all to the same folder .. or perhaps file
them in predefined folders such as 0 to 9 (the first digit of the
unique ID).

Job done!

Just thought I'd post this in case anyone was curious as to how I got
around the problem.

Feb 1 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.