SAVE IMAGE IN DATABASE IN A SEQUENCE WAY LIKE 1.JPG,2.JPG..MVC
SQLCOMMAND="select SF_SLNO from tbl_NONTEACHING_STAFF where SF_SLNO=(select MAX(SF_SLNO) from tbl_NONTEACHING_STAFF)";
SqlConnection con = new SqlConnection(con1);
SqlDataAdapter sqa = new SqlDataAdapter(command, con);
DataSet ds = new DataSet();
sqa.Fill(ds);
string fimg = null; string simg = null; string lastvalue;
string fimgextension = file.FileName.ToString().Substring(file.FileName.ToString().LastIndexOf('.') + 1);
if (ds.Tables[0].Rows.Count > 0)
{
lastvalue = ds.Tables[0].Rows[0][0].ToString().Substring(ds.Tables[0].Rows[0][0].ToString().LastIndexOf('/') + 1);
string[] arr = lastvalue.Split('.');
string fileimg = arr[0];
string imgextension = arr[0];
int fstimg = Convert.ToInt32(fileimg) + 1;
int sndimg = fstimg + 1;
file.SaveAs(Server.MapPath("~/ntfpic/") + fstimg + "." + fimgextension);
fimg = "~/ntfpic/" + fstimg + "." + fimgextension;
}
else
{
file.SaveAs(Server.MapPath("~/ntfpic/") + "1" + "." + fimgextension);
fimg = "~/ntfpic/" + "1" + "." + fimgextension;
}
return fimg;
}
here fimg will contain your image address
SqlDataAdapter sqa = new SqlDataAdapter(command, con);
DataSet ds = new DataSet();
sqa.Fill(ds);
string fimg = null; string simg = null; string lastvalue;
string fimgextension = file.FileName.ToString().Substring(file.FileName.ToString().LastIndexOf('.') + 1);
if (ds.Tables[0].Rows.Count > 0)
{
lastvalue = ds.Tables[0].Rows[0][0].ToString().Substring(ds.Tables[0].Rows[0][0].ToString().LastIndexOf('/') + 1);
string[] arr = lastvalue.Split('.');
string fileimg = arr[0];
string imgextension = arr[0];
int fstimg = Convert.ToInt32(fileimg) + 1;
int sndimg = fstimg + 1;
file.SaveAs(Server.MapPath("~/ntfpic/") + fstimg + "." + fimgextension);
fimg = "~/ntfpic/" + fstimg + "." + fimgextension;
}
else
{
file.SaveAs(Server.MapPath("~/ntfpic/") + "1" + "." + fimgextension);
fimg = "~/ntfpic/" + "1" + "." + fimgextension;
}
return fimg;
}
here fimg will contain your image address
so save it like :
ntf.NSF_IMAGE=fimg;
NOTE: ntfpic is here folder name where your image will be saved
THATS ALL
THANKS FOR READING
No comments:
Post a Comment