selvi subramanian

selvi subramanian

  • NA
  • 799
  • 570.9k

Hi i need to upload a photo using asp.net c#.... it shows some error like dis

Mar 29 2012 6:58 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class AdminModule_EmployeeRegistration : System.Web.UI.Page
{
   
    BUAL Acc = new BUAL();
    REMO obj = new REMO();
    //string dt;
    string dob;
    int j,k,l;
    String fname, fpath;
    String spath;
    string FleNme = "";
    public string SaveLocation = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        MultiView1.SetActiveView(View1);
        MaritalStatus();
        Gen();
        date();
        SkillLevel();
    }
    //protected void Button1_Click(object sender, EventArgs e)
    //{
    //    dt = Date.SelectedItem.ToString() +"/"+ Month.SelectedItem.ToString() +"/"+ Year.SelectedItem.ToString();
    //    Acc._FirstName = txtfname.Text;
    //    Acc._LastName = txtlastnm.Text;
    //    Acc._FatherName = txtfathername.Text;
    //    Acc._Dob = dt;
    //    Acc._MartialStatus = ddlmartial.SelectedItem.ToString();
    //    Acc._Address = txtaddress.Text;

    //    Acc._MobileNo = txtmobileno.Text;
    //    Acc._EmailId = txtemailid.Text;
    //    Acc._State = txtstate.Text;
    //    Acc._District = txtdistrict.Text;
    //    Acc._CompanyName = txtcompanyname.Text;
    //    Acc._Designation = ddldestination.SelectedItem.ToString();
    //    Acc._YearOfExp = txtYOExp.Text;

    //    Acc._CompanyAddress = txtcompanyaddre.Text;
    //    Acc._SkillSet = txtskillset.Text;
    //    Acc._SkillLevel = ddlskilllevel.SelectedItem.ToString();
    //    Acc._ContactPerson = txtcontactper.Text;
    //    Acc._ContactNo = txtcontactno.Text;
    //    Acc._UserName = txtusername.Text;
    //    Acc._Password = txtpassword.Text;
    //    Acc._ConfirmPassword = txtconfirmpassword.Text;
    //    lblmessage.Text = Acc.Login(Acc._FirstName, Acc._LastName, Acc._FatherName, Acc._Dob, Acc._MartialStatus, Acc._Address, Acc._MobileNo, Acc._EmailId, Acc._State, Acc._District, Acc._CompanyName, Acc._Designation, Acc._YearOfExp, Acc._CompanyAddress, Acc._SkillSet, Acc._SkillLevel, Acc._ContactPerson, Acc._ContactNo, Acc._UserName, Acc._Password, Acc._ConfirmPassword);
    //    // Response.Redirect("~/TeamLeaderModule/welcome.aspx");

    //}


    //private void clear()
    //{
    //    txtfname.Text = "";
        
    //    txtfathername.Text = "";
       
    //    txtaddress.Text = "";
    //    txtmobileno.Text = "";
    //    txtemailid.Text = "";
    //    txtstate.Text = "";
    //    txtdistrict.Text = "";
    //    txtcompanyname.Text = "";
    //    txtYOExp.Text = "";
    //    txtcompanyaddre.Text = "";
    //    txtskillset.Text = "";
    //    txtcontactper.Text = "";
    //    txtcontactno.Text = "";
    //    txtusername.Text = "";
    //    txtpassword.Text = "";
    //    txtconfirmpassword.Text = "";

    //}
    public void MaritalStatus()
    {
        ListItem li = new ListItem();
        li.Value = "0";
        li.Text = "select";
        ddlmarital.Items.Add(li.ToString());

        ddlmarital.Items.Add("Single");
        ddlmarital.Items.Add("Widow");
        ddlmarital.Items.Add("Married");
        ddlmarital.Items.Add(li.ToString());
    }
    private void Gen()
    {
        if (RadioButton1.Checked)
        {
            Acc._Gender = "Male";
        }
        else
        {
            Acc._Gender = "Female";
        }

    }
    private void Type()
    {
       if(RadioButton3.Checked)
    {
        Acc._ChooseType="Referal";
    }
           else
           {
               Acc._ChooseType="NonReferal";
           }

    }
    public void Resume()
    {

        if (FileUpload1.HasFile)
        {
            //Check File is available in Fileupload control and then upload to server path
            fname = FileUpload1.FileName;
            spath = @"~\Uploaded\" + FileUpload1.FileName;
            fpath = Server.MapPath("Uploaded");
            fpath = fpath + @"\" + FileUpload1.FileName;
           
            if (System.IO.File.Exists(fpath))
            {
                Label41.Text = "File Name already exists!";
                return;
            }
            else
            {
                FileUpload1.SaveAs(fpath);
            }
            //Store details in the SQL Server table
          
        }
        else
        {
            Label41.Text = "Please select file!";
        }
    }
    public void Join()
    {

        if (FileUpload2.HasFile)
        {
            //Check File is available in Fileupload control and then upload to server path
            fname = FileUpload2.FileName;
            spath = @"~\Uploaded\" + FileUpload2.FileName;
            fpath = Server.MapPath("Uploaded");
            fpath = fpath + @"\" + FileUpload2.FileName;

            if (System.IO.File.Exists(fpath))
            {
                Label42.Text = "File Name already exists!";
                return;
            }
            else
            {
                FileUpload2.SaveAs(fpath);
            }
            //Store details in the SQL Server table

        }
        else
        {
            Label42.Text = "Please select file!";
        }
    }
    //public void Photo()
    //{

    //    if (FileUpload3.HasFile)
    //    {
    //        //Check File is available in Fileupload control and then upload to server path
    //        fname = FileUpload3.FileName;
    //        spath = @"~\Uploaded\" + FileUpload3.FileName;
    //        fpath = Server.MapPath("Uploaded");
    //        fpath = fpath + @"\" + FileUpload3.FileName;

    //        if (System.IO.File.Exists(fpath))
    //        {
    //            Label40.Text = "File Name already exists!";
    //            return;
    //        }
    //        else
    //        {
    //            FileUpload3.SaveAs(fpath);
    //        }
    //        //Store details in the SQL Server table

    //    }
    //    else
    //    {
    //        Label40.Text = "Please select file!";
    //    }
    //}



    public void SkillLevel()
    {

        ListItem li = new ListItem();
        ddlskilllevel.Items.Add("Begginer");
        ddlskilllevel.Items.Add("Excellent");
        ddlskilllevel.Items.Add("Normal");


        ddlskilllevel.Items.Add(li.ToString());

    }
    public void date()
    {




        for (j = 1; j <= 31; j++)
        {
            ListItem li2 = new ListItem();
            li2.Text = Convert.ToString(j);
            li2.Value = Convert.ToString(j);
            Date.Items.Add(li2.ToString());
        }
        for (k = 1; k <= 12; k++)
        {
            ListItem li3 = new ListItem();
            li3.Text = Convert.ToString(k);
            li3.Value = Convert.ToString(k);
            Month.Items.Add(li3.ToString());

        }
        for (l = 1980; l <= 2020; l++)
        {
            ListItem li4 = new ListItem();
            li4.Text = Convert.ToString(l);
            li4.Value = Convert.ToString(l);
            Year.Items.Add(li4.ToString());

        }
    }



  
    protected void RadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        MultiView4.SetActiveView(View4);
        MultiView1.Visible = false;
        MultiView2.Visible = false;
        MultiView3.Visible = false;
    }
    protected void RadioButton1_CheckedChanged(object sender, EventArgs e)
    {
       
        MultiView3.SetActiveView(View3);
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        dob = Date.SelectedItem.ToString() + '/' + Month.SelectedItem.ToString() + '/' + Year.SelectedItem.ToString();
        MaritalStatus();
        Gen();
      
        Acc._EmployeeName = txtfname.Text;
        Acc._FatherName = txtfathername.Text;
        //Acc._Gender = RadioButton1.ToString();
        //Acc._Gender = RadioButton2.ToString();
        //Acc._DOB = Date.SelectedItem.ToString();
        //Acc._DOB = Month.SelectedItem.ToString();
        Acc._DOB = dob;
        Acc._MaritalStatus = ddlmarital.SelectedItem.ToString();
        Acc._Address = txtaddress.Text;
        Acc._MobileNo = txtmobileno.Text;
        Acc._EmailId = txtemailid.Text;
        Acc._State = txtstate.Text;
        Acc._District = txtdistrict.Text;
        Acc.Personal(Acc._EmployeeName,Acc._FatherName,Acc._Gender,Acc._DOB,Acc._MaritalStatus,Acc._Address,Acc._MobileNo,Acc._EmailId,Acc._State,Acc._District);
        MultiView2.SetActiveView(View2);
        MultiView1.Visible = false;
        DataSet ds=new DataSet();
        string qry = "select EmployeeId from PersonalDetails where EmailId='"+txtemailid.Text+"' ";
        ds = obj.GETDS(qry);
        Label10.Text = ds.Tables[0].Rows[0]["EmployeeId"].ToString();

    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        Type();
        Resume();
        Join();
        //Photo();

        FleNme = System.IO.Path.GetFileName(FileUpload3.PostedFile.FileName.ToString());
        string SaveLocation = Server.MapPath("Photo") + "\\" + FleNme;
        if (FileUpload3.PostedFile != null)
        {

            FileUpload3.PostedFile.SaveAs(SaveLocation);

        }






        Acc._EmployeeId = Label10.Text;
        Acc._EmployeePhoto = FileUpload3.ToString();
        Acc._CompanyName = txtcompanyname.Text;
        Acc._CompanyAddress = txtcompanyaddre.Text;
        Acc._YearOfExp = txtYOExp.Text;
        Acc._Domain = txtdomain.Text;
        Acc._SkillSet = txtskillset.Text;
        Acc._SkillLevel = ddlskilllevel.Text;
        Acc._CompanyEmailId = txtcontactper.Text;
        Acc._CompanyPhoneNo = txtcontactno.Text;
        Acc._UploadResume=FileUpload1.ToString();
        Acc._DOJ = TextBox1.Text;
        Acc._JoiningReport=FileUpload2.ToString();
        Acc._Name = TextBox3.Text;
        Acc._ContactNo = TextBox4.Text;
        Acc._Company = TextBox5.Text;
        Acc._EmailAddress = TextBox6.Text;
        Acc.Experience(Acc._EmployeeId, Acc._EmployeePhoto, Acc._CompanyName, Acc._CompanyAddress, Acc._YearOfExp, Acc._Domain, Acc._SkillSet, Acc._SkillLevel, Acc._CompanyEmailId, Acc._CompanyPhoneNo, Acc._UploadResume, Acc._DOJ, Acc._JoiningReport, Acc._ChooseType, Acc._Name, Acc._ContactNo, Acc._Company, Acc._EmailAddress);





        MultiView4.SetActiveView(View4);
        MultiView2.Visible = false;
        MultiView3.Visible = false;
        MultiView1.Visible = false;

    }
   
}




it Shows the error

Server Error in '/RMCR1' Application.

The filename, directory name, or volume label syntax is incorrect.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.


Source Error: 

Line 308:        { Line 309: Line 310:            FileUpload3.PostedFile.SaveAs(SaveLocation); Line 311: Line 312:        }

Source File: c:\RMCR1\AdminModule\EmployeeRegistration.aspx.cs    Line: 310 

Stack Trace: 

[IOException: The filename, directory name, or volume label syntax is incorrect. ]    System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +7717004    System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy) +1162    System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +61    System.IO.FileStream..ctor(String path, FileMode mode) +55    System.Web.HttpPostedFile.SaveAs(String filename) +99    AdminModule_EmployeeRegistration.Button3_Click(Object sender, EventArgs e) in c:\RMCR1\AdminModule\EmployeeRegistration.aspx.cs:310    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565 


Version Information: Microsoft .NET Framework Version:2.0.50727.5448; ASP.NET Version:2.0.50727.5456
 














Answers (3)