upload控制項上傳json檔案合并的兩種方法

來源:互聯網
上載者:User

標籤:style   blog   io   color   os   sp   檔案   div   on   

方法一:

 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 = new byte[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 = "檔案上傳失敗!";            }

 

upload控制項上傳json檔案合并的兩種方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.