首页 > Web开发 > 详细

SharePoint2013和2010 webparth上传附件到其他列表(ViewState实现)

时间:2014-02-26 03:33:57      阅读:384      评论:0      收藏:0      [点我收藏+]

SharePoint2013和2010

webparth上传附件到其他列表

前台:

bubuko.com,布布扣
 <div>
    <asp:FileUpload ID="FileUpload2" runat="server" />
    <asp:Button ID="Button3" runat="server" Text="上传" OnClick="Button1_Click" />
    共上传<asp:Label ID="Label2" runat="server"></asp:Label><asp:Button ID="Button4" runat="server" onclick="Button4_Click" Text="审批" />
     <br />
    <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
bubuko.com,布布扣

 

bubuko.com,布布扣
  protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                ViewState["demo"] = 0;
            }
            
        }
        
     
        protected void Button1_Click(object sender, EventArgs e)
        {
           string FileName = FileUpload2.PostedFile.FileName;
           if (FileName == "")
           {
               Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), string.Format("<script>alert(‘上传文件不能为空!‘)</script>"));
           }
           else
           {
               string file_KB = FileUpload2.PostedFile.ContentLength.ToString() + "KB<br>";//获取文件大小
               string file = FileUpload2.FileName;//获取上传文件名字
               ViewState["demo"] = Convert.ToInt32(ViewState["demo"]) + 1;//ViewState["demo"]获取个数

               string URL = "http://amid01110/456/" + file + " ";



               string lntext = "<a  href=‘" + URL + "‘  >" + file + "</a>" + "大小" + file_KB + "上传文件成功";



               Label1.Text += Label1.Text.Length > 0 ? "<br />" + lntext : lntext;

               Label2.Text = ViewState["demo"].ToString();
           }
        }

        protected void Button4_Click(object sender, EventArgs e)
        {

            this.UploadFileToDocLib(SPContext.Current.Web, "发送记录", Page.Request["ID"]);//实例化网站,添加的列表名,点开的列表的id
        }
        public void UploadFileToDocLib(SPWeb web, string docLibName, string chname)
        {
            web.AllowUnsafeUpdates = true;//设置允许更改
            SPListItem li = web.Lists["新建"].GetItemById(int.Parse(chname));//点开的列表名和点开的id 
            SPList jl = web.Lists.TryGetList(docLibName);//实例化列表名称
            
            SPListItem it = jl.Items.Add();
            it["标题"] = li["标题"];

            it["附件文件"] = Label1.Text.ToString();
           
            it.Update();
            //li.Delete();
        }
bubuko.com,布布扣

SharePoint2013和2010 webparth上传附件到其他列表(ViewState实现)

原文:http://www.cnblogs.com/914556495wxkj/p/3567309.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!