日期:2014-05-17  浏览次数:20615 次

asp.net 文件上传

 DataTable dt2 = ViewState["dt2"] as DataTable;

            for (int i = 0; i < dt2.Rows.Count; i++)
            {
                FileInfo file = new FileInfo(dt2.Rows[i]["photo_path"].ToString());
                Stream stream = file.OpenRead();
                //int index = SourceFilePath.LastIndexOf("\\", SourceFilePath.Length - 1);
                string SourceFilePath = this.hidPath1.Value;

                int index = SourceFilePath.LastIndexOf("\\", SourceFilePath.Length - 1);
                string strFileName = SourceFilePath.Substring(index + 1);


                if (stream.CanRead)
                {
                    using (FileStream fs = new FileStream(newPath + strFileName, FileMode.Create))
                    {
                        byte[] buffer = new byte[stream.Length];
                        int totalLength = (int)stream.Length;
                        int readLength = 0;
                        stream.Position = 0;
                        while (totalLength > 0)
                        {
                            int readCount = stream.Read(buffer, readLength, Math.Min(totalLength, int.MaxValue));
                            if (readCount == 0)
                            {
               &n