void CreateDataItem(int index, bool bReadOnly, bool bAllowDownd, UploadViewDataItem item, HtmlTextWriter writer) { if (item != null) { TableRow row = new TableRow(); row.CssClass = (index % 2 == 0) ? this.DataItemNormalClass : this.DataItemAlterClass; TableCell cell = null; if (!bReadOnly) { cell = new TableCell(); cell.HorizontalAlign = HorizontalAlign.Center; HtmlInputCheckBox chk = new HtmlInputCheckBox(); chk.ID = chk.Name = string.Format("{0}_CHK_{1}", this.ClientID, item.FileID); chk.Value = item.FileID; cell.Controls.Add(chk); row.Cells.Add(cell); } string downloadBaseURI = this.DownloadBaseURI; if (bAllowDownd && !this.UploadRaws.ContainsKey(item.FileID) && !string.IsNullOrEmpty(downloadBaseURI)) { cell = new TableCell(); cell.HorizontalAlign = HorizontalAlign.Left; HtmlAnchor a = new HtmlAnchor(); a.InnerText = string.Format("{0}.{1}", index + 1, item.FileName); string[] exts = this.OfficeSuffix.Split('|'); if (!this.ReadOnly && this.AllowOfficeOnlineEdit && exts != null && exts.Length > 0 && (Array.BinarySearch(exts, item.Extension.ToLower()) > -1)) { string url = string.Empty; if (downloadBaseURI.IndexOf("/") > 0) url = downloadBaseURI.Substring(0, downloadBaseURI.LastIndexOf("/")); if (string.IsNullOrEmpty(url)) url = string.Format("http://{0}/", HttpContext.Current.Request.Url.Host); url = string.Format("{0}{1}{2}", url, item.FileID, item.Extension); a.HRef = "#"; a.Attributes["onclick"] = string.Format("javascript:UploadView_DocumentEdit('{0}');", url); } else { a.HRef = string.Format("{0}{1}", downloadBaseURI, item.FileID); a.Target = "_blank"; } cell.Controls.Add(a); row.Cells.Add(cell); } else { cell = new TableCell(); cell.HorizontalAlign = HorizontalAlign.Left; cell.Text = string.Format("{0}.{1}", index + 1, item.FileName); row.Cells.Add(cell); } cell = new TableCell(); cell.HorizontalAlign = HorizontalAlign.Left; cell.Text = item.Extension; row.Cells.Add(cell); cell = new TableCell(); cell.HorizontalAlign = HorizontalAlign.Right; cell.Text = item.Size < 0.01 ? "< 0.01" : string.Format("{0:N2}", item.Size); row.Cells.Add(cell); row.RenderControl(writer); } }
void BuildItems(ICollection dataSource) { if (dataSource != null) { IEnumerator enumerator = dataSource.GetEnumerator(); PropertyDescriptorCollection pdc = null; PropertyDescriptor pd = null; StringCollection allFileID = new StringCollection(); while (enumerator.MoveNext()) { object obj = enumerator.Current; if (obj != null) { pdc = TypeDescriptor.GetProperties(obj); if (pdc != null && pdc.Count > 0) { bool flag = false; UploadViewDataItem item = new UploadViewDataItem(); pd = pdc.Find(this.FileIDField, true); if (pd != null) { item.FileID = new GUIDEx(pd.GetValue(obj)); allFileID.Add(item.FileID); flag = true; } pd = pdc.Find(this.FileNameField, true); if (pd != null) { item.FileName = Convert.ToString(pd.GetValue(obj)); flag &= true; } pd = pdc.Find(this.ExtensionField, true); if (pd != null) { item.Extension = Convert.ToString(pd.GetValue(obj)); flag &= true; } pd = pdc.Find(this.SizeField, true); if (pd != null) item.Size = Convert.ToDouble(pd.GetValue(obj)); if (flag) this.Items.Add(item); } } } this.FileIDFromDataSource = allFileID; } }
void BuildItems(DataTable dtSource) { if (dtSource != null) { StringCollection allFileID = new StringCollection(); foreach (DataRow row in dtSource.Rows) { UploadViewDataItem item = new UploadViewDataItem(); item.FileID = new GUIDEx(row[this.FileIDField]); allFileID.Add(item.FileID); item.FileName = Convert.ToString(row[this.FileNameField]); item.Extension = Convert.ToString(row[this.ExtensionField]); item.Size = Convert.ToDouble(row[this.SizeField]); this.Items.Add(item); } this.FileIDFromDataSource = allFileID; } }
bool SaveUpload() { if (this.HasFile) { try { HttpPostedFile postedFile = this.PostedFile; UploadViewDataItem item = new UploadViewDataItem(); item.FileID = GUIDEx.New; item.FileName = Path.GetFileName(postedFile.FileName); item.Extension = Path.GetExtension(postedFile.FileName); item.Size = (double)(postedFile.ContentLength / (double)1024 / (double)1024); if (this.MaxUploadSize > 0) { if (item.Size > this.MaxUploadSize) throw new Exception(string.Format("上传文件为{0:N2}Mb超过了允许上传的最大上限({1:N2}Mb)!", item.Size, this.MaxUploadSize)); } if (this.MaxUploadCount > 0) { if (this.Items.Count + 1 > this.MaxUploadCount) throw new Exception(string.Format("上传的文件个数({0}个)超过了允许上传的最大个数({1}个)。", this.Items.Count + 1, this.MaxUploadCount)); } this.Items.Add(item); this.SaveFileRawToPage(item.FileID, postedFile.ContentType, postedFile.InputStream); return true; } catch (Exception e) { this.OnUploadViewExceptionEvent(e); } } return false; }