Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
any one help this
what is this error am trying to view image from Database
 
Path cannot be null.
Parameter name: path
 
this is my code....
 protected void btnMulSave_Click(object sender, ImageClickEventArgs e)
        {
            if (txtMulName.Text == "")
            {
                string str1 = "Name field cannot be left blank!!!";
                ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('" + str1 + "');", true);
            }
            else
            {
                if (txtMulName.Text == ddlparent.Text)
                {
                    msgmulliteral.Text = "Municipal Name and its Parent Node cannot be same.";
                }
 
                else
                {
 
                    if (fileup.HasFile)
                    {
                        file = fileup.FileName;
                        bool ans = checkFileExtension(file);
                        if (ans)
                        {
                            try
                            {
                                int length = fileup.PostedFile.ContentLength;
                                byte[] imgbyte = new byte[length];
                                HttpPostedFile img = fileup.PostedFile;
                                img.InputStream.Read(imgbyte, 0, length);
                                string imagename = txtMulShortName.Text;
                                SqlConnection connection = new SqlConnection("server=.......;user id=.....;password=....;database=IMADB");
                                connection.Open();
                                SqlCommand cmd = new SqlCommand("INSERT INTO tbllocationdetails (fileup) VALUES (@loclogo)", connection);
                                //cmd.Parameters.Add("@ImageNAme", SqlDbType.VarChar, 50).Value = imagename;
                                cmd.Parameters.Add("@loclogo", SqlDbType.Image).Value = imgbyte;
                                int count = cmd.ExecuteNonQuery();
                                connection.Close();
                            }
 
                                //fileadd = (Server.MapPath("Image\\") + txtMulShortName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString());
                            //fileup.SaveAs(fileadd);

                            catch (Exception ex) { }
                            locLogo.ImageUrl = "~/Image/" + txtMulName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString();
                        }
                        else
                        {
                            msgmulliteral.Text = "Invalid file type of Logo, select only JPG files";
                        }
 
                    }
                    if (ddlparent.Text != "None")
                    {
                        DataSet ds = PDataset("select locid from tbllocation where locname='" + ddlparent.Text + "'");
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            mylocation.parentID = dr["locid"].ToString();
                        }
                    }
                    else
                    {
                        mylocation.parentID = "AA0000";
                    }
 
                    if (chkMulActive.Checked)
                    {
                        mylocation.active = true;
                    }
                    else
                    {
                        mylocation.active = false;
                    }
 
                    if (chkMulLogical.Checked)
                    {
                        mylocation.logical = true;
                    }
                    else
                    {
                        mylocation.logical = false;
                    }
                    //Find Previous Entry

                    DataSet d = PDataset("select locpkid, locname from tbllocation where locid='" + txtMunicipalID.Text + "'");
                    DataTable da = d.Tables[0];
                    if (da.Rows.Count > 0)
                    {
                        //Update
                        string str = "UPDATE tbllocation SET "+
                            "locparentid ='" + mylocation.parentID.ToString() + "', " +
                            "locname ='" + txtMulName.Text + "', " +
                            "locactive='" + mylocation.active + "', " + 
                            "userstatus='" + mylocation.logical + "', " + 
                            "locupdate='" + DateTime.Now.ToString() + "', " +
                            "locshortdesc='" + txtMulShortName.Text + "', " +
                            "locdesc='" + txtMulDescription.Text + "' " +
                        "where locpkid='" + da.Rows[0]["locpkid"].ToString() + "'";
                        
                        string updetail = "update tbllocationdetails set locwebsite='" + txtMulWebSite.Text + "', locmanager='" + ddlmanager.Text + "' where locpkid='" + da.Rows[0]["locpkid"].ToString() + "'";
 
                        
                        SqlConnection conn = new SqlConnection(clsconnection.getConnectionString());
                        SqlCommand cmd = new SqlCommand(str, conn);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        cmd.CommandText = updetail;
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
 
                    else
                    {
                        //Add New
                        mylocation.ID = txtMunicipalID.Text;
                        mylocation.Name = txtMulName.Text;
                        mylocation.Shorname = txtMulShortName.Text;
                        mylocation.description = txtMulDescription.Text;
 

                        mylocation.manager = ddlmanager.SelectedValue;
                        mylocation.website = txtMulWebSite.Text;
 
                        if (fileup.HasFile)
                        {
                            FileStream fs;
                            fs = new FileStream(fileadd, FileMode.Open, FileAccess.Read);
                            byte[] picbyte = new byte[fs.Length];
                            fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
                            fs.Close();
                            mylocation.fileupload = picbyte;
                        }
                        mylocation.locInsert();
                        clearalltextboxes();
                        Addnew();
                        msgmulliteral.Text = "Data Added Successfully";
                        
                    }
                    Response.Redirect("wpaLocationDetails.aspx");
                    rightpanelbtn(false);
                    leftpanelbtn(true);
                }
            }
}
Posted 17-Feb-12 0:20am
Edited 17-Feb-12 0:22am
v2
Comments
rockpune at 17-Feb-12 5:26am
   
Server Error in '/' Application.
Path cannot be null.
Parameter name: path
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.ArgumentNullException: Path cannot be null.
Parameter name: path
 
Source Error:
 
Line 276: {
Line 277: FileStream fs;
Line 278: fs = new FileStream(fileadd, FileMode.Open, FileAccess.Read);
Line 279: byte[] picbyte = new byte[fs.Length];
Line 280: fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
Jaganathan Bantheswaran at 17-Feb-12 5:36am
   
fileadd is null i guess. i couldn't see any assignment to fileadd variable
rockpune at 17-Feb-12 5:40am
   
plz tell me what can i do am newly learnig .net plz help me
Jaganathan Bantheswaran at 17-Feb-12 5:41am
   
Just conform whether the fileadd is null or not by debugging the app.
rockpune at 17-Feb-12 5:45am
   
not null sir.....loclogo(image,not null)
Technoses at 17-Feb-12 5:48am
   
do you want to display imageor save image in database
rockpune at 17-Feb-12 5:49am
   
i want to view image from DB acctully am viewing from folder inserted images
Technoses at 17-Feb-12 5:52am
   
what is "mylocation"
and what do you want to do with below code
if (fileup.HasFile)
{
FileStream fs;
fs = new FileStream(fileadd, FileMode.Open, FileAccess.Read);
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
mylocation.fileupload = picbyte;
}
rockpune at 17-Feb-12 5:54am
   
table name sir
rockpune at 17-Feb-12 5:55am
   
i have to view iamge from DB
Technoses at 17-Feb-12 5:56am
   
mylocation.fileupload ????
table name ??
which table
Jaganathan Bantheswaran at 17-Feb-12 5:48am
   
loclogo(image,not null)...?
rockpune at 17-Feb-12 5:52am
   
sql table... for image storing.... columname=loclogo,datatype=image,allownull=not
rockpune at 17-Feb-12 6:17am
   
columname=loclogo,datatype=image,allownull=not
Jaganathan Bantheswaran at 17-Feb-12 5:49am
   
i am asking whether the fileadd variable is null or not?
rockpune at 17-Feb-12 5:55am
   
null
rockpune at 17-Feb-12 5:57am
   
sorry not null
Technoses at 17-Feb-12 5:58am
   
if fileadd is null then
you should assign name of file
Jaganathan Bantheswaran at 17-Feb-12 5:56am
   
fileadd variable should not be NULL.
Technoses at 17-Feb-12 6:00am
   
mylocation.fileupload ????
table name ??
which table
Technoses at 17-Feb-12 6:02am
   
?????
rockpune at 17-Feb-12 6:04am
   
mylocation=table name,
DB=IMADB
image storing.... columname=loclogo,datatype=image,allownull=not
Technoses at 17-Feb-12 6:03am
   
are you using class "mylocation" to save data
rockpune at 17-Feb-12 6:05am
   
mylocation=tablename
rockpune at 17-Feb-12 6:05am
   
select * from tbllocationdetails
Technoses at 17-Feb-12 6:04am
   
the code below you using like that you are saving data
 
if (fileup.HasFile)
{
FileStream fs;
fs = new FileStream(fileadd, FileMode.Open, FileAccess.Read);
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
mylocation.fileupload = picbyte;
}
mylocation.locInsert();
clearalltextboxes();
Addnew();
msgmulliteral.Text = "Data Added Successfully";
is this for save or not
Technoses at 17-Feb-12 6:08am
   
is this :"mylocation" you table name
than how u use "mylocation.ID" "ID" as a property
i m confused ???
rockpune at 17-Feb-12 6:13am
   
tbllocationdetails=table name
rockpune at 17-Feb-12 6:09am
   
yes for saving but i have to view from DB
Technoses at 17-Feb-12 6:10am
   
if you want to save image then
you should use "fileup"
what is "fileup" ??
is this file upload controle or...???
Technoses at 17-Feb-12 6:15am
   
you have commented the code
//fileadd = (Server.MapPath("Image\\") + txtMulShortName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString());
//fileup.SaveAs(fileadd);
why???
 
you save file then read file from server by
 
FileStream fs;
fs = new FileStream(fileadd, FileMode.Open, FileAccess.Read);
 
and file not found so
fs is null
 
you can use
 
fileup.PostedFile.InputStream as a Stream to convert it to byte
in place of
first you save file on server then read from file stream....
Technoses at 17-Feb-12 6:18am
   
the error above is not in viewing file
but in saving file in db

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

you have commented the code
//fileadd = (Server.MapPath("Image\\") + txtMulShortName.Text + "." + file.Substring(file.LastIndexOf(".") + 1).ToString());
                            //fileup.SaveAs(fileadd);
why???
you save file then read file from server by
FileStream fs;
   fs = new FileStream(fileadd, FileMode.Open, FileAccess.Read);
and file not found so
fs is null
you can use
 
fileup.PostedFile.InputStream as a Stream to convert it to byte
in place of
first you save file on server then read from file stream....
  Permalink  
v2
Comments
Anuja Pawar Indore at 17-Feb-12 7:50am
   
Added pre tag and formatting done

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Richard MacCutchan 269
1 Aajmot Sk 252
2 Marcin Kozub 235
3 Sergey Alexandrovich Kryukov 185
4 Praneet Nadkar 167
0 OriginalGriff 7,913
1 Sergey Alexandrovich Kryukov 7,232
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,865


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 17 Feb 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100