File Uploading permission

M

Mukesh

Hi all
I am trying to upload and save as a picture to "root/Photos" folder in
my web application.
I am using this code to perform this task

DirectoryInfo strFolder = new DirectoryInfo("/Photos/");
if (!strFolder.Exists)
{
strFolder.Create();
}

fu12.PostedFile.SaveAs(strFolder.tostring()+"abc.jpg");



but the script is not working i think it is access permission

Can any body help me

I am Using Asp.net 2.0 VS2005 Environment
 
Z

zee

U need to specify server.mapPath like this

DirectoryInfo strFolder = new
DirectoryInfo(Server.MapPath("").ToString()+@"\photos\");
if (!strFolder.Exists)
{
strFolder.Create();
}

fileUpld.PostedFile.SaveAs(strFolder.ToString() +
"abc.jpg");

tc
 
S

Steve C. Orr [MCSD, MVP, CSM, ASP Insider]

For an ASP.NET application to effectively manage files, it must have
permission to access these files. By default ASP.NET runs under a user
account named ASPNET under WinXP, or NetworkService under Win2003. This
user account has very limited permissions. It will not be able to interact
with most of the server's file system by default, and it won't have access
to any network shares either. Therefore you'll want to give the ASPNET user
account the folder permissions it needs, or have ASP.NET use a different
user account that does have the necessary permissions.
You can adjust the user account from within IIS, or you can configure
Impersonation in the web.config file or the machine.config file. For
initial experimentation and debugging I'd suggest having ASP.NET run under
your user account since you know what files you have permission to access.

<!-- Web.config file. -->
<identity impersonate="true"/>
<identity impersonate="true" userName="Redmond\BillG" password="Melinda"/>
 
S

Steven Cheng[MSFT]

Hello Mukesh,

As for your file uploading issue, what's the upload directory's position?
Is it under your application's root directory or in another place on the
machine? Also, would you add some particular access permission control on
it or simply allow your ASP.NET application to have full control over it?

Generally, for your scenario, you can check the following two things first:

1. Whether your save file code has refer to the correct directory path.

In ASP.NET application, if you want to reference a sub directory under your
application root directory, you can use the "~/subdir" style path and user
Server.MapPath to map it to physical path. e.g.

protected void Page_Load(object sender, EventArgs e)
{
string path = Server.MapPath("~/uploadfiles/");
Request.Files[0].SaveAs(path +
Path.GetFileName(Request.Files[0].FileName));
}


2. If the path is correct, you can check your ASP.NET worker process's
security identity to see whether it has the sufficient permission to access
the target directory. The ASP.NET process identity mode is different
between IIS5 and IIS6(IIS5 use MACHINE\ASPNET account while IIS6 use NT
AUTHORITY\NETWORK SERVICE by default), you can refer to the following
reference:

#Configuring ASP.NET Process Identity
http://msdn2.microsoft.com/en-us/library/dwc1xthy.aspx

After you get your ASP.NET application's executing account(security
identity), you can check its access permission to the directory you want to
save file.

Please feel free to post here if there is anything unclear.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.



Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================



This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hello Mukesh,

Have you got any progress on this issue? If you have any further question,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Similar Threads


Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top