473,387 Members | 1,592 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,387 software developers and data experts.

File Uploading permission

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.j pg");

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
Dec 18 '06 #1
4 29774
zee
U need to specify server.mapPath like this

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

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

tc

Dec 18 '06 #2
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"/>

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net

"Mukesh" <ef*****@newsgroups.nospamwrote in message
news:uV**************@TK2MSFTNGP02.phx.gbl...
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.j pg");

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
Dec 18 '06 #3
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/subscripti...ult.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/subscripti...t/default.aspx.

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

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



Dec 19 '06 #4
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.

Dec 21 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Seb | last post by:
Hi, I've got something strange when uploading files on a UNIX machine with PHP 4.3.4 + Apache 1.3.29 : The uploaded file is uploaded in /va/tmp with permissions 600 (that's normal) ...
1
by: Kareem Badr | last post by:
I was having permission problems, so I'm using a test file to make sure uploading works. upload.php successfully uploads a file to the images/bookcovers dir: <html> <form method="post"...
4
by: R Reyes | last post by:
I am trying to code a file uploader (for forum/email attachments) from the client computer to a remote web server via the PUT method (since POST is not allowed ). However, the upload works ONLY...
6
by: jackson | last post by:
Hi all, Im having problem when uploading file to localhost. but I can upload to drive c: any idea thanks
7
by: russell.lane | last post by:
I've been looking at both MTOM and simple HTTP POST or PUT for file uploads. Some relevant details: ... We want to support programmatic file uploads from Winform apps. ... The files are large...
3
acoder
by: acoder | last post by:
How to Upload a File in Coldfusion Use the cffile tag for uploading files to the server. Note that allowing people to upload files is fraught with danger and only trusted users should be...
2
by: Ramanichandran | last post by:
Dear all, Could u please give some idea. The issue is, in web page while uploading a file it will give eror. Microsoft VBScript runtime error '800a0046' ...
1
by: lPrentice | last post by:
Hello, After all this time, Linux file permissions still confuse me at times. I have a Python web-based application with an file (images) upload module. The application is running on two remote...
5
by: kailashchandra | last post by:
I am trying to upload a file in php,but it gives me error msg please Help me? My Code is like below:- i have one php file named upload.php and i have another html file named upload.html and...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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:
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.