473,386 Members | 1,698 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Problem creating folder in C# Asp.Net

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
7 4067
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Alexander Berezhnoy | last post by:
Hi all ! I want to try MS Visual Studio NET. My system - Windows 2003 Server . IIS (WWW) is started. WWW http://localhost in my IE working normal. But - after trying to build new project in...
3
by: Dave Y | last post by:
Hello, I am new to ASP as well as IIS. I am trying to learn how to create a web application using asp.NET. I have followed the instructions for configuring the IIS settings but when I click on...
6
by: Eran Kampf | last post by:
I am trying to dynamically create directories in my ASP.NET application (I am using Server.MapPath("/")+"test" as the folder) and I am getting a DirectoryNotFoundException saying "Could not find a...
1
by: Thanks | last post by:
I have a routine that is called on Page_Init. It retrieves folder records from a database which I display as Link Buttons in a table cell. I set the table cell's bgcolor to a default color (say...
8
by: nick | last post by:
I have a problem and I've been using a cheezy work around and was wondering if anyone else out there has a better solution. The problem: Let's say I have a web application appA. Locally, I set...
7
by: tonelab | last post by:
I have an aspx page that does not have a separate source for the VB - it is on top in between the <script> tags. I use the following statement Dim oComLib as New ComLib To reference a class...
2
by: Richard Lionheart | last post by:
Hi All, I generated a WebForm and created a Virtual Directory for it IIS. But I got an error message (shown below) saying something like my app lacked appropriate privileges. David Wang...
1
by: BG | last post by:
Hey All, Using VB.Net Standard 2003. WIN 2000/Pro & WIN XP Pro 2002. Trying to create an ASP.Net web app out on the server that I lease from. Steps that I'm using... ...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
1
by: Ana RM | last post by:
Mark.Powell@eds.com (Mark D Powell) wrote in message news:<2687bb95.0308010642.1fc4ff1f@posting.google.com>... Hi Mark, Thanks por answer me. I do not think it is important thw warehouse...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.