Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

File Upload in asp.net

Posted on 2012-04-04
10
Medium Priority
?
623 Views
Last Modified: 2012-08-14
Hi I want users to be able to upload files to the server.

The code I have used to work on old server. But I now get error

Access to the path 'E:\web\mysite\artwork\testimage.jpg' is denied.

I have read on the internet that I need to give permisson to folder through IIS7 but can not see where to do this.

I am quite new to asp.net so please explain in detail.
0
Comment
Question by:taz8020
[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
  • 2
  • 2
  • +1
10 Comments
 
LVL 6

Expert Comment

by:ingriT
ID: 37805913
You have to give Windows access to this path, so this has nothing to do with IIS or ASP.NET.

On the server you go to the folder, right click and set access permissions for the user that is running your site, probably the ASP.NET user.
0
 
LVL 3

Author Comment

by:taz8020
ID: 37806015
Hi its a shared web server winhost.com, how would I go about logging in? you can view the folder by going to mywebsite.com/artwork/ but can not right to it. Winhost says by defualt it should be read write?
0
 
LVL 6

Expert Comment

by:ingriT
ID: 37806062
Did you put the files and the folder for users to upload to on there with an FTP application? You should check the folder access there, see if it is all read-write (or 777 or something like that).
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 9

Expert Comment

by:Seven price
ID: 37806502
You should be able to do this dynamically without giving permission for example.

create function for folder
public string CheckStoreDirectoryExists()
{


      string IntraDir = HttpContext.Current.Server.MapPath("\\foldername\\");
      System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(IntraDir);

      if (!di.Exists) {
            di.Create();
      }

      di = null;
      return IntraDir;

}
0
 
LVL 9

Expert Comment

by:Seven price
ID: 37806520
client side the code below requires no permissions
<p id="upload-area"><input id="File2" type="file" size="50" name="File1" runat="server">
                        </p>
                        <asp:button id="btnSubmit" onclick="btnSubmit_Click" runat="server" Text="Upload Now"></asp:button>
                  

string FileName = "name of file you could make dynamic";
string IntraDir = CheckStoreDirectoryExists();
HttpFileCollection uploads = HttpContext.Current.Request.Files;
for (i = 0; i <= uploads.Count - 1; i++) {
      HttpPostedFile FileToUpload = uploads(i);
      ///*********************************/
      // Error Handling here error
      ///*********************************/
      if ((FileToUpload.ContentLength == 0)) {
            var _with1 = lblMessage;
            lblMessage.Visible = true;
            _with1.CssClass = "labelGreen";
            _with1.Text = "Sorry there is no File to Upload please try again.";
      } else {
            FileName = System.IO.Path.GetFileName(FileToUpload.FileName);
            try {
                  FileToUpload.SaveAs(IntraDir + "\\" + FileInfo);
                  //Server.Transfer("UploadComplete.aspx?id=" + (Request.QueryString("id")))
                  var _with2 = lblMessage;
                  lblMessage.Visible = true;
                  _with2.CssClass = "labelgreen";
                  _with2.Text = "Thank you, for your file";

            } catch (Exception ex) {
                  var _with3 = lblMessage;
                  lblMessage.Visible = true;
                  _with3.CssClass = "labelRed";
                  _with3.Text = "Sorry there is no File to Upload please try again.";
            }
      }
}
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37807615
Most hosting companies provide a way of setting permissions on your site subfolders(1&1 allows me to do that). You would need to login to your control panel and set permissions on Artwork folder using their utility.

http://forum.winhost.com/showthread.php?t=5477
0
 
LVL 3

Author Comment

by:taz8020
ID: 37814225
Hi thanks all but still no wiser. I have set web.config to full trust as recommended by winhost. They also said to make sure membership is setup correctly. But with in the asp.net configeration I can not see any where to set folder permissions. The control pannel does not have anything saying about folder permissions.

Also in the forum it says that by default all folders and sub folders are set to read right.

It works fine on local machine so can not be the code must be a setting somewhere.
Any other ideas?
0
 
LVL 3

Author Comment

by:taz8020
ID: 37814338
Thanks all but now got to the bottom of it
If you have used Web Deploy to publish your site, contact support and ask
them to reset your ASPNet IUSR's ACL permission.

As when using web public it need to lock the permissions but should unlock them once done.
0
 
LVL 3

Author Comment

by:taz8020
ID: 37814640
I've requested that this question be closed as follows:

Accepted answer: 0 points for taz8020's comment #37814338

for the following reason:

because its correct
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 37814641
>If you have used Web Deploy to publish your site, contact support and ask them to reset your ASPNet IUSR's ACL permission.

That's what I meant by folder permissions. I am sure they have a way of setting these ACLs from the control panel. You can accept you comment as the answer but my suggestion was correct as well so include that as assisted.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

609 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