Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > problem in uploading

Reply
Thread Tools

problem in uploading

 
 
fa_2064@yahoo.com
Guest
Posts: n/a
 
      07-15-2006
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.FileNa me.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\\imag es\\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>");
}


}
}

}

 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      07-17-2006
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() <> "" AndAlso fileUpload.PostedFile.ContentLength
> 0 Then

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
http://www.velocityreviews.com/forums/(E-Mail Removed)
http://www.nathansokalski.com/

<(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.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.FileNa me.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\\imag es\\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>");
}


}
}

}


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ftp uploading vs. control panel uploading Dung Ping HTML 10 01-16-2006 10:43 AM
problem in uploading and downloading files from DB in ASP.Net =?Utf-8?B?SGltYW5zaHU=?= ASP .Net 4 07-01-2005 08:16 AM
Problem after uploading in domain =?Utf-8?B?U3VkaXA=?= ASP .Net 0 06-29-2005 01:15 PM
Problem Uploading templated documents to SQL Server in ASP.net Lou ASP .Net 1 08-17-2004 04:01 AM
Uploading files using ASP.NET problem darin dimitrov ASP .Net 3 06-22-2004 07:38 PM



Advertisments