//文件写入流 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();}上传的文件格式不限。 追问 c#窗口能不能上传?
<tr> <td width="60%" align="right"> <asp:FileUpload ID="UserFile" runat="server" /> </td> <td align="left" > <asp:Button ID="UserImport" runat="server" Text="学生人员信息导入" onclick="UserImport_Click" /> </td> </tr> protected void UserImport_Click(object sender, EventArgs e) { string fileName = UserFile.FileName; 获取上传的文件的名称 string path = Server.MapPath("~/ImportExcelFile/"); //存储在服务器的路径 if (!Directory.Exists(path)) //判断路径是否存在 不存在创建 { Directory.CreateDirectory(path); } string savePath = path + fileName; 这是 文件保存到服务器 文件的整体路径 UserFile.SaveAs(savePath); 上传保存OK }简单易懂明白了吗?希望帮到你 追问 c#窗口能不能上传? 追答 我没试过啊 帅哥!!你试下就知道了