taz8020
asked on
File Upload in asp.net
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\tes timage.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.
The code I have used to work on old server. But I now get error
Access to the path 'E:\web\mysite\artwork\tes
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.
ASKER
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?
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).
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(" \\folderna me\\");
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(In traDir);
if (!di.Exists) {
di.Create();
}
di = null;
return IntraDir;
}
create function for folder
public string CheckStoreDirectoryExists(
{
string IntraDir = HttpContext.Current.Server
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(In
if (!di.Exists) {
di.Create();
}
di = null;
return IntraDir;
}
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.Reques t.Files;
for (i = 0; i <= uploads.Count - 1; i++) {
HttpPostedFile FileToUpload = uploads(i);
///*********************** ********** /
// Error Handling here error
///*********************** ********** /
if ((FileToUpload.ContentLeng th == 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 (FileToUpl oad.FileNa me);
try {
FileToUpload.SaveAs(IntraD ir + "\\" + FileInfo);
//Server.Transfer("UploadC omplete.as px?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.";
}
}
}
<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.Reques
for (i = 0; i <= uploads.Count - 1; i++) {
HttpPostedFile FileToUpload = uploads(i);
///***********************
// Error Handling here error
///***********************
if ((FileToUpload.ContentLeng
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
try {
FileToUpload.SaveAs(IntraD
//Server.Transfer("UploadC
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.";
}
}
}
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
http://forum.winhost.com/showthread.php?t=5477
ASKER
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?
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?
ASKER
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.
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.
ASKER
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
Accepted answer: 0 points for taz8020's comment #37814338
for the following reason:
because its correct
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.