C#从数据把文件下载在硬盘,文件名的问题
我这样往硬盘里写放入文件,那么给每个文件不同的文件名。我这样写的,不管有多少文件,始终只读一个文件啊,高手指点啊。我想在这里把系统作为文件名。Application.StartupPath + ("\\Temp\\.jpg"), 因为现在只能读一个文件。对不住了啊,新手没有分。我的分值为0了
struct Employee
{
public string PictureFile;
public string Page;
}
class DownFile
{
MyMeans MyMean = new MyMeans();
MyModule MyModule = new MyModule();
string My_con = MyMeans.M_str_sqlcon;
public void treeView1_AfterSelect()
{
int CurRec = 0; //初始化记录计数器
//int rec_count=0; //计算总记录数
//public PictureFiles;
string i = System.DateTime.Now.ToString();
Directory.CreateDirectory(Application.StartupPath + "\\Temp\\"+i);
try
{
SqlConnection conn = new SqlConnection(My_con);
string sql = "select COUNT(*) from PICTURE";
///string sql = "select UNITID ,PICTUREFILE from PICTURE order by UNITID";
SqlDataReader AD = MyMean.getcom(sql);
AD.Read();
int a = Convert.ToInt32(AD[0].ToString());
// int a = AD.GetByte(0).ToString();
conn.Open();
//SqlDataReader dr = null;
Employee[] tuser = new Employee[a];
sql = "select PAGEID ,UNITNAME,PICTUREFILE from PICTURE order by PAGEID";
// SqlCommand cmd = new SqlCommand(sql, conn);
// cmd = new SqlCommand(sql, conn);
SqlDataReader dr = MyMean.getcom(sql);
while (dr.Read())//(dr.HasRows)
{
tuser[CurRec].PictureFile = i + dr["PAGEID"].ToString();
tuser[CurRec].Page = i + dr["UNITNAME"].ToString();
byte[] bytes = ((byte[])dr["PICTUREFILE"]);
FileStream fs = new FileStream(Application.StartupPath + ("\\Temp\\.jpg"), FileMode.Create, FileAccess.Write);
BinaryWriter bw1 = new BinaryWriter(fs);
bw1.Write(bytes, 0, bytes.Length);
fs.Flush();
fs.Close();
CurRec += 1;
}
dr.Close();
conn.Close();
}
catch (Exception ex)
{
MessageBox.Show("下载文件发生异常 : " + ex.Message);
}
}