problem in uploading

F

fa_2064

hi every body
when i run this code i receive this error! my "wwwroot" folder is
shared, but i don't know what it's reason is!!!
{"Access to the path
\"D:\\Inetpub\\wwwroot\\iranian\\images\\user_imgs\\Untitled-1.jpg\" is
denied." }

is there a way that the url be relative???

my code is:

public void btnupload_ServerClick(object sender, System.EventArgs e)
{
string uploadFolder =
"D:\\Inetpub\\wwwroot\\iranian\\images\\user_imgs\\" ;
if (!(filename.PostedFile.FileName == "")){
filename.Value.Insert(0,filename.PostedFile.FileName.ToString()) ;
}
System.IO.FileInfo objfile;
objfile= new System.IO.FileInfo(filename.Value);
if (!objfile.Exists){
HttpContext.Current.Response.Write("<script
language=javascript>alert('! Ùایل انتخابی وجود
ندارد');</script>");
}else{

string sPath = uploadFolder;
string fname = filename.Value;
int pos;
string extension;

pos = fname.LastIndexOf(".");
extension = (fname.Substring(pos + 1)).ToLower();
if (!( extension == "jpg" ) | (pos == -1)){
HttpContext.Current.Response.Write("<script
language=javascript>alert('!(*.jpg ) نوع Ùایل انتخابی
معتبر نمی باشد');</script>");
}else{
int inroot;
inroot =
fname.IndexOf("D:\\Inetpub\\wwwroot\\iranian\\images\\user_imgs\\", 0);
//build file info for display

pos = fname.LastIndexOf("\\");
fname = fname.Substring(pos + 1);
sPath += fname;
try
{
if (filename.PostedFile != null)
{
filename.PostedFile.SaveAs(sPath);
Application.Add("fname", sPath);
}
}
catch(System.Exception exc)
{
HttpContext.Current.Response.Write("<script
language=javascript>alert('! مشکلی در جایگزینی
تصویر وجود دارد');</script>");
}


}
}

}
 
N

Nathan Sokalski

First, I would check to make sure that the proper account (usually 'ASPNET')
has write access to the desired directory. Also, it looks like you are
making things much more complicated for yourself than necessary. Here is
some simple code that uploads a file:


'fileUpload is a System.Web.UI.HtmlControls.HtmlInputFile

If fileUpload.Value.Trim() said:
fileUpload.PostedFile.SaveAs(Server.MapPath("./") &
IO.Path.GetFileName(fileUpload.PostedFile.FileName))

End If



Here is an explanation of the code:


The If statement tests to make sure something was entered in fileUpload and
that the file actually has some content. The SaveAs method is used to save
the file to the server. The parameter is the full path of where you want it
saved. You will notice that I generated this string by concatenating the
directory and filename. To get the full path I used the Server.MapPath
method which takes a relative path/directory (in my example I use ./ which
is the current directory) and returns the full path/directory. To get the
filename, I used the GetFileName method which takes a path as a parameter
and returns just the filename (in my example I simply pass it the FileName
property of the PostedFile. If you have any questions about this (or if I
entirely misunderstood your problem), feel free to let me know. Good Luck!
--
Nathan Sokalski
(e-mail address removed)
http://www.nathansokalski.com/

hi every body
when i run this code i receive this error! my "wwwroot" folder is
shared, but i don't know what it's reason is!!!
{"Access to the path
\"D:\\Inetpub\\wwwroot\\iranian\\images\\user_imgs\\Untitled-1.jpg\" is
denied." }

is there a way that the url be relative???

my code is:

public void btnupload_ServerClick(object sender, System.EventArgs e)
{
string uploadFolder =
"D:\\Inetpub\\wwwroot\\iranian\\images\\user_imgs\\" ;
if (!(filename.PostedFile.FileName == "")){
filename.Value.Insert(0,filename.PostedFile.FileName.ToString()) ;
}
System.IO.FileInfo objfile;
objfile= new System.IO.FileInfo(filename.Value);
if (!objfile.Exists){
HttpContext.Current.Response.Write("<script
language=javascript>alert('! ???? ??????? ????
?????');</script>");
}else{

string sPath = uploadFolder;
string fname = filename.Value;
int pos;
string extension;

pos = fname.LastIndexOf(".");
extension = (fname.Substring(pos + 1)).ToLower();
if (!( extension == "jpg" ) | (pos == -1)){
HttpContext.Current.Response.Write("<script
language=javascript>alert('!(*.jpg ) ??? ???? ???????
????? ??? ????');</script>");
}else{
int inroot;
inroot =
fname.IndexOf("D:\\Inetpub\\wwwroot\\iranian\\images\\user_imgs\\", 0);
//build file info for display

pos = fname.LastIndexOf("\\");
fname = fname.Substring(pos + 1);
sPath += fname;
try
{
if (filename.PostedFile != null)
{
filename.PostedFile.SaveAs(sPath);
Application.Add("fname", sPath);
}
}
catch(System.Exception exc)
{
HttpContext.Current.Response.Write("<script
language=javascript>alert('! ????? ?? ????????
????? ???? ????');</script>");
}


}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top