[WebMethod]
public int downloadimg(string sort,int sort_id)
{
string constr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
string imagename = "";
try
{
con.Open();
SqlCommand com = new SqlCommand("select id,img from photo where "
+ "sort_id=" + sort_id.ToString(), con);
SqlDataReader dr = com.ExecuteReader(CommandBehavior.CloseConnection);
int k = 0;
while (dr.Read())
{
String id = dr["id"].ToString().Trim();
MemoryStream ms = new MemoryStream((Byte[])dr["img"]);
Bitmap image = new Bitmap(ms);
string filepath = Server.MapPath("upload/");
DirectoryInfo dir = new DirectoryInfo(filepath);
FileInfo[] filecount = dir.GetFiles();
imagename = filepath + "k"+k.ToString();
image.Save(imagename);
k++;
}
dr.Close();
return k;
}
catch
{
return -1;
}
finally
{
con.Close();
}
}