upload控件上传json文件合并的两种方法
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了upload控件上传json文件合并的两种方法,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2706字,纯文字阅读大概需要4分钟。
内容图文
![upload控件上传json文件合并的两种方法](/upload/InfoBanner/zyjiaocheng/1123/17327c2cfe2949bc9c3f8d42ba453873.jpg)
方法一:
byte[] byte1 = FileUpload1.FileBytes; byte[] byte2 = FileUpload2.FileBytes; byte[] a1 = Encoding.UTF8.GetBytes("["); byte[] a2 = Encoding.UTF8.GetBytes(","); byte[] a3 = Encoding.UTF8.GetBytes("]"); byte[] totalaa = newbyte[a1.Length + byte1.Length + a2.Length + byte2.Length + a3.Length]; a1.CopyTo(totalaa, 0); byte1.CopyTo(totalaa, a1.Length); a2.CopyTo(totalaa, a1.Length + byte1.Length); byte2.CopyTo(totalaa, a1.Length + byte1.Length + a2.Length); a3.CopyTo(totalaa, a1.Length + byte1.Length + a2.Length + byte2.Length); string total1 = Encoding.UTF8.GetString(totalaa);
方法二:
string fileName = Path.GetFileNameWithoutExtension(FileUpload1.PostedFile.FileName); //获取文件名(不包括扩展名)string Extension1 = Path.GetExtension(FileUpload1.PostedFile.FileName);//扩展名string Extension2 = Path.GetExtension(FileUpload2.PostedFile.FileName); if (Extension1 == "" || Extension2 == "") { Response.Write("<script>alert(‘请添加文件‘);</script>"); return; } if (FileUpload1.PostedFile.FileName == FileUpload2.PostedFile.FileName) { Response.Write("<script>alert(‘请添加不同的文件‘);</script>"); return; } if (Extension1.ToLower() != ".txt" || Extension2.ToLower() != ".txt") { Response.Write("<script>alert(‘文件后缀名不正确!请输入txt的文件‘);</script>"); return; } if (Directory.Exists(Server.MapPath("~/UploadFile")) == false)//判断文件夹是否存在,若不存在则创建 { Directory.CreateDirectory(Server.MapPath("~/UploadFile")); } string UploadFilePath = Server.MapPath("UploadFile\\"); string fullName = FileUpload1.PostedFile.FileName; string newName = DateTime.Now.ToString("yyyyddmmhhss") + fullName.Substring(fullName.LastIndexOf(".")); FileUpload1.SaveAs(UploadFilePath + FileUpload1.PostedFile.FileName); FileUpload2.SaveAs(UploadFilePath + FileUpload2.PostedFile.FileName); FileStream fs = new FileStream(UploadFilePath + newName, FileMode.Create); string line1 = string.Empty; string line2 = string.Empty; using (StreamReader sr1 = new StreamReader(UploadFilePath + FileUpload1.PostedFile.FileName)) { line1 = sr1.ReadToEnd(); } using (StreamReader sr2 = new StreamReader(UploadFilePath + FileUpload2.PostedFile.FileName)) { line2 = sr2.ReadToEnd(); } try { string total = "[" + line1 + "," + line2 + "]"; StreamWriter sw = new StreamWriter(fs); sw.Write(total); sw.Flush(); sw.Close(); fs.Close(); if (File.Exists(UploadFilePath + FileUpload1.PostedFile.FileName)) { File.Delete(UploadFilePath + FileUpload1.PostedFile.FileName); } if (File.Exists(UploadFilePath + FileUpload2.PostedFile.FileName)) { File.Delete(UploadFilePath + FileUpload2.PostedFile.FileName); } showmessage.InnerText = "文件上传成功!"; } catch { showmessage.InnerText = "文件上传失败!"; }
原文:http://www.cnblogs.com/zxiong/p/4106477.html
内容总结
以上是互联网集市为您收集整理的upload控件上传json文件合并的两种方法全部内容,希望文章能够帮你解决upload控件上传json文件合并的两种方法所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。