473,378 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

problem in uploading

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>");
}


}
}

}

Jul 15 '06 #1
1 1398
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
nj********@hotmail.com
http://www.nathansokalski.com/

<fa*****@yahoo.comwrote in message
news:11*********************@b28g2000cwb.googlegro 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>");
}
}
}

}
Jul 17 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mike | last post by:
Hi i have a problem in asp.ne i am uploading file to the server using htmlinput controls and every thing is o but i try to upload larger file to the server like more than 4 mb and about 10mb i got...
1
by: Jonathan | last post by:
Hi everyone, I have a problem with the file uploading in Asp.Net and I have read a lot on forums on this but never found an answer. Here is the problem: I know Asp.Net maximum Length for...
4
by: Himanshu | last post by:
hi, Can anybody tell me that thru asp.net using c#, how can we upload and download physical files in any table of SQL Server Database. the uploading part is running successfully but the...
7
by: Ankit Aneja | last post by:
I put the code for url rewrite in my Application_BeginRequest on global.ascx some .aspx pages are in root ,some in folder named admin and some in folder named user aspx pages which are in user...
4
by: Ramakrishnan Nagarajan | last post by:
Hi, I am facing a different problem in my application. In that I am uploading a folder that contain only images. Everything was done and was working fine too. When I executed the application using...
3
by: Carlos | last post by:
Hello Forum, I would appreciate it if you could recommend settings to use auto-vacuum in my version 7.4 database. I am uploading several thousands records in the database at a rate of ~1 second...
0
by: Ramakrishnan Nagarajan | last post by:
Hi, I am facing a problem in uploading Excel data to the Database. While uploading my code reads Excel Data using OleDbReader and store into a dataset by looping through the OleDbReader result...
7
by: jambroo | last post by:
Hello, We are currently having issues uploading files using PHP. It seems files below 8MB are uploaded fine, however files above 8.2MB cause the page to timeout or show a 'Cannot find server or...
3
ganesanji
by: ganesanji | last post by:
hi all, I have written a php coding for uploading a file to a specific folder or location in server which is a Linux server. I think the coding for file uploaing is correct. But it does not...
2
by: Bremanand | last post by:
Hi folks, i am working in C# , i have problem while uploading the file to FTP which has size around 4MB. The code which comes after the bold area is not executed.. here am...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.