Click here to Skip to main content
15,910,277 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Expert,

I am uploading image file using asp.net FileUpload control.

I am using following code.

C#
try
        {
            string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
            string fileLocation = Server.MapPath("~/images/"  + fileName);


                FileUpload1.SaveAs(fileLocation);

        }
        catch(Exception ex)
        {
            Response.Write(ex.StackTrace.ToString());
        }</pre>


Locally it working fine for me.
but on server it
FileUpload1.SaveAs(fileLocation);
throws following exception

at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in :0 at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize) [0x00000] in :0 at (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare,int) at System.IO.File.Create (System.String path, Int32 bufferSize) [0x00000] in :0 at System.IO.File.Create (System.String path) [0x00000] in :0 at System.Web.HttpPostedFile.SaveAs (System.String filename) [0x00000] in :0 at nridubai_admin_tstFileUpload.Button5_Click (System.Object sender, System.EventArgs e) [0x00000] in :0


Please note that i am using mono platform on server.

Please help me.

Thanks in advance
Posted
Comments
[no name] 26-Apr-12 8:31am    
Have you verified the ASP.NET user has access to the upload location?
udusat13 26-Apr-12 8:38am    
Thanks.
yes.because i ahve uploaded image with php code successfully.
But FileUpload.saveAs() giving that error.

1 solution

try to set necessary permissions for aspnet accout

Regards
Sebastian
 
Share this answer
 
Comments
udusat13 26-Apr-12 8:39am    
Thanks for reply me.

Please tell me how to set permission.
I am new to asp.net
Sebastian T Xavier 26-Apr-12 8:46am    
find out which OS you are using? find out which is the name for aspnet account(related to securities tab). give full access for the folder containg image.
udusat13 11-May-12 8:03am    
thanks.........
now its working
Sebastian T Xavier 11-May-12 8:44am    
thanks. good to know you have figured it out...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900