problem in uploading

Discussion in 'ASP .Net' started by fa_2064@yahoo.com, Jul 15, 2006.

  1. Guest

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


    }
    }

    }
     
    , Jul 15, 2006
    #1
    1. Advertising

  2. 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.nathansokalski.com/

    <> wrote in message
    news:...
    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>");
    }


    }
    }

    }
     
    Nathan Sokalski, Jul 17, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. darin dimitrov

    Uploading files using ASP.NET problem

    darin dimitrov, Jun 22, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    849
    darin dimitrov
    Jun 22, 2004
  2. Lou
    Replies:
    1
    Views:
    353
    Scott Allen
    Aug 17, 2004
  3. =?Utf-8?B?SGltYW5zaHU=?=

    problem in uploading and downloading files from DB in ASP.Net

    =?Utf-8?B?SGltYW5zaHU=?=, Jun 25, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    710
    =?Utf-8?B?SGltYW5zaHU=?=
    Jul 1, 2005
  4. =?Utf-8?B?U3VkaXA=?=

    Problem after uploading in domain

    =?Utf-8?B?U3VkaXA=?=, Jun 29, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    413
    =?Utf-8?B?U3VkaXA=?=
    Jun 29, 2005
  5. Dung Ping
    Replies:
    10
    Views:
    995
    Chaddy2222
    Jan 16, 2006
Loading...

Share This Page