234cfds1 发表于 2015-9-25 12:07:05

[原]SharePoint文档库上传文档

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using Microsoft.SharePoint;
namespace WebApplication4
{
    public partial class _Default : System.Web.UI.Page
    {
      protected void Page_Load(object sender, EventArgs e)
      {
      }
      protected void Button1_Click(object sender, EventArgs e)
      {
            using (SPSite site = new SPSite("http://zhangyi:90"))
            {
                using (SPWeb web = site.OpenWeb())
                {
                  web.AllowUnsafeUpdates = true;
                  Stream fStream = this.FileUpload1.PostedFile.InputStream;
                  byte[] contents = new byte;
                  fStream.Read(contents, 0, (int)fStream.Length);
                  fStream.Close();
                  string filename = FileUpload1.PostedFile.FileName;
                  //filename = filename.Substring(filename.LastIndexOf("\\"));
                  web.Files.Add("http://zhangyi:90/DocLib1/test2.xml", contents, true);
                  Response.Write("OK");
                  
                }
            }
      }
    }
}
页: [1]
查看完整版本: [原]SharePoint文档库上传文档