[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

ASP.NET C# file upload failing

Posted on 2009-04-01
4
Medium Priority
?
906 Views
Last Modified: 2012-05-06
I am using an asp:FileUpload controll to upload a file via a c# website to an IIS server running on a Windows Server 2003 machine but ive hit a bit of a snag.

The files i am trying to upload have restricted access permissions which are limited to a select handfull of specific users, not including the aspnet user. As far as i was aware the browser posts the file and as the browser is being run by one of the files allowed users the file should be posted to the server with no issues. This however does not seem to be the case, the file does not upload, i have tried changing the file to give the aspnet user permissions and the file then uploads with no issues. The aspnet user has access to the location where the files will be saved.

Hence i am now asking for your kind assistance in order to help me solve this issue. I also have one further question which may decide the outcome for me which is as follows; i have a crystal report viewer running on the website which will later view these files when they have been uploaded, if the file permissions are restricted as such will the report viewer be unable to display the file?

I have posted my upload code below, thankyou in advance.
protected bool SubmitUpload()
    {
        try
        {
            if (uplRptLoc.PostedFile != null && uplRptLoc.PostedFile.ContentLength > 0 &&
                uplRptLoc.PostedFile.FileName.Substring(uplRptLoc.PostedFile.FileName.Length - 4) == ".rpt")
            {
                // match the report path and uploaded file name and upload file
                string reportDirectory = Huntercombe.Configuration.ReportPath;
                string fileName = System.IO.Path.GetFileName(uplRptLoc.PostedFile.FileName);
                this.uplRptLoc.PostedFile.SaveAs(System.IO.Path.Combine(reportDirectory, fileName));
 
                return true;
            }
            else
            {
                return false;
            }
        }
        catch
        {
            return false;
        }
    }

Open in new window

0
Comment
Question by:sypher1987
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 23

Expert Comment

by:apresto
ID: 24039685
As far as i am aware the ASPnet user needs to have access to the directory you are uploading to
0
 
LVL 7

Expert Comment

by:davidmuto
ID: 24039692
How about giving the Network Service account modify rights to the upload directory...worked for me.
0
 
LVL 26

Accepted Solution

by:
Anurag Thakur earned 750 total points
ID: 24039742
use impersonation i.e. run your website under a user who has rights to write to the folder where you are uploading the files to
to do that there are 2 methods
add impersonation tag in the web.config
or in the IIS change the user under which the website runs to the user who has got permissions
0
 
LVL 9

Expert Comment

by:Gorkem Yuksel
ID: 24039868
Hi,

If the file is larger than 4 MB, then you need to modify your web.config to allow for larger file sizes.  By default, anything over 4 MB will fail.

To increase the size to something more realistic, edit the HttpRuntime tag in your web.config file.  If one doesn't exist, you can create one.

It may already have additional attributes, but the one to ensure is: maxRequestLength

The HttpRuntime tag should like something like this to accept files upto 50MB:  
*note that the entry is in KB*

<HttpRuntime maxRequestLength="51200" />

Cheers,

G.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question