文件转为二进制流
FileStream fs =new FileStream(strFile,FileMode.OpenOrCreate, FileAccess.Read);
Byte[] img = new Byte[fs.Length];

fs.Read(img, 0, Convert.ToInt32(fs.Length));
二进制流写入文件
MemoryStream ms =new System.IO.MemoryStream(mybyte);
Bitmap b =(Bitmap)Image.FromStream(ms);

b.Save(filePath,ImageFormat.Png);
多图片上传
private void button3_Click(object sender, EventArgs e)
{
dlZipDir();


}
private void dlZipDir()//string strPath, string strFileName)
{
string strPath = @"C:\Documents and Settings\wuy\桌面\DataModelMapping_20060925_01";

String strBaseDir = "";
MemoryStream ms = null;
ms = new MemoryStream();
zos = new ZipOutputStream(ms);
//zos = new ZipOutputStream(File.Create(outname));
strBaseDir = strPath + "\\";
addZipEntry(strBaseDir);
zos.Finish();
zos.Close();
}
private void addZipEntry(string PathStr)
{
DirectoryInfo di = new DirectoryInfo(PathStr);
foreach (DirectoryInfo item in di.GetDirectories())
{
addZipEntry(item.FullName);
}
foreach (FileInfo item in di.GetFiles())
{
FileStream fs = File.OpenRead(item.FullName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string strEntryName = item.FullName.Replace("aa", "");
ZipEntry entry = new ZipEntry(strEntryName);
zos.PutNextEntry(entry);
zos.Write(buffer, 0, buffer.Length);
fs.Close();
}
}
FileStream fs =new FileStream(strFile,FileMode.OpenOrCreate, FileAccess.Read);
Byte[] img = new Byte[fs.Length];
fs.Read(img, 0, Convert.ToInt32(fs.Length));
MemoryStream ms =new System.IO.MemoryStream(mybyte);
Bitmap b =(Bitmap)Image.FromStream(ms);
b.Save(filePath,ImageFormat.Png);
private void button3_Click(object sender, EventArgs e)
{
dlZipDir();

}
private void dlZipDir()//string strPath, string strFileName)
{
string strPath = @"C:\Documents and Settings\wuy\桌面\DataModelMapping_20060925_01";
String strBaseDir = "";
MemoryStream ms = null;
ms = new MemoryStream();
zos = new ZipOutputStream(ms);
//zos = new ZipOutputStream(File.Create(outname));
strBaseDir = strPath + "\\";
addZipEntry(strBaseDir);
zos.Finish();
zos.Close();
}
private void addZipEntry(string PathStr)
{
DirectoryInfo di = new DirectoryInfo(PathStr);
foreach (DirectoryInfo item in di.GetDirectories())
{
addZipEntry(item.FullName);
}
foreach (FileInfo item in di.GetFiles())
{
FileStream fs = File.OpenRead(item.FullName);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
string strEntryName = item.FullName.Replace("aa", "");
ZipEntry entry = new ZipEntry(strEntryName);
zos.PutNextEntry(entry);
zos.Write(buffer, 0, buffer.Length);
fs.Close();
}
}

浙公网安备 33010602011771号