//文件写入流
private void ReadFile()
{
Byte[] MesageFile;
string path =@"c:\123.XML";
FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
int size = Convert.ToInt32(stream.Length);
MesageFile = new Byte[size];
stream.Read(MesageFile, 0, size);
stream.Close()
string fileName =path.Substring(path.LastIndexOf("\\") + 1, path.Length path.LastIndexOf("\\") - 1);
WriteFile(MesageFile, fileName);
}
//写入文件
private void WriteFile(Byte[] fileByte,string fileName)
{
string path = AppDomain.CurrentDomain.BaseDirectory + "\\UpLoad\\" + DateTime.Now.ToString("yyyy-MM-dd")+"\\";
if (!Directory.Exists(path))
Directory.CreateDirectory(path);
string savepath = path + fileName;
FileStream fos = new FileStream(savepath, FileMode.OpenOrCreate, FileAccess.ReadWrite);
fos.Write(MesageFile, 0, MesageFile.Length);
fos.Close();
}
上传的文件格式不限。
fileupload控件
用 filestream
戴尔服务器分销。