由于现在写的aspx是以内容类型发布到moss的,后台代码用Inherits的方法继承。并且在moss中无法(不想修改moss本身的webconfig,改了也不知道有没有效果)修改webconfig里的<httpRuntime maxRequestLength="409600" executionTimeout="3600"></httpRuntime>,所以我把上传的部分放在webservice里来实现。
但是问题出现了,在别人机器上上传不知怎么的有时候快,有时候慢的要死,所以想做一个进度条。
然而,这毕竟不像在asp.net里这么自由的放上别人的控件显示进度条,网上有很多例子关于分块处理,但是看着自己的代码不知道怎么改了。
具体代码如下:
- C# code
protected void btnfileup_Click(object sender, EventArgs e)//客户调用 { WS.shouwen sw = new shouwenDLL.WS.shouwen(); byte[] fileContent = fileup.FileBytes;//网上说这里一次性读到内存,所以慢,但是,这个代码中应该怎样分块处理呢? string fileName = fileup.FileName; if(sw.checkFileInDB(fileName,Session["fida"].ToString()) == false)//检查是否已经上传 { string fida = sw.UploadFile(fileContent, fileName, 0).ToString();//让webservice实行上传,并且插入数据库,多上传用。 Session["fida"] += fida + ","; BindDL(Session["fida"].ToString().TrimEnd(',')); } }
上传功能,有数据库操作
- C# code
[WebMethod(MessageName = "文件上传")] public int UploadFile(byte[] fs, string fileName, int id) { try { System.IO.MemoryStream m = new System.IO.MemoryStream(fs); string year = DateTime.Now.Year.ToString(); string month = DateTime.Now.Month.ToString(); string serverPath = "\\" + year + "\\" + month + "\\" + DateTime.Now.ToLongTimeString().Replace(':','_') + "\\"; string serverPsyPath = System.Configuration.ConfigurationManager.AppSettings["AttachmentPath"].ToString() + serverPath; if (!Directory.Exists(serverPsyPath)) { Directory.CreateDirectory(serverPsyPath); } string strFile = serverPsyPath + fileName; System.IO.FileStream fl = new System.IO.FileStream(strFile, FileMode.OpenOrCreate); m.WriteTo(fl); m.Close(); fl.Close(); m = null; fl = null; return FileInsertDB(id, fileName, serverPath); } catch (Exception ex) { string exStr = ex.ToString(); return 0; } } public int FileInsertDB(int id, string fileName,string serverPath) { serverPath = serverPath.Replace('\\', '/'); //申明:文件虚拟路径按照年月分eg:/2009/12/ string insertSql = "SET NOCOUNT ON;INSERT fileup (id,filename,path) values ('{0}','{1}','{2}');SELECT SCOPE_IDENTITY() AS ida;"; insertSql = string.Format(insertSql, id, fileName, serverPath); return int.Parse(db.ExecuteDataSet(CommandType.Text, insertSql).Tables[0].Rows[0]["ida"].ToString()); }
跪求各位大侠帮忙,还有分没有了,请楼主赐分
qq:444266832
------解决方案--------------------
为什么这个帖子不存在sharepoint?