Sharepoint 2010 SharePoint 2010

Sharepoint 2010 SharePoint 2010,sharepoint-2010,Sharepoint 2010,我们正在完成一项任务,使用SharePoint 2010创建一个web应用程序,这对我们所有人来说都是全新的 我的挑战是创建一个文件上传表单。我使用SharePoint designer从ASP.NET工具箱中拖动upload文本框和按钮控件。我不知道下一步该怎么办,因为我需要这些文件去我想去的地方 以下是我在页面上使用的控件的代码: <form id="form1" runat="server"> <asp:FileUpload runat="server" id="File

我们正在完成一项任务,使用SharePoint 2010创建一个web应用程序,这对我们所有人来说都是全新的

我的挑战是创建一个文件上传表单。我使用SharePoint designer从ASP.NET工具箱中拖动upload文本框和按钮控件。我不知道下一步该怎么办,因为我需要这些文件去我想去的地方

以下是我在页面上使用的控件的代码:

<form id="form1" runat="server">
<asp:FileUpload runat="server" id="FileUpload1" /><br />
<br />
<asp:Button runat="server" Text="Upload" id="Button1" Width="88px" />
</form>




假设您在页面上实现了FileUpload控件,则此例程将上载单个文件。该例程从FileUpload控件获取文件名,并将其添加到SharePoint列表:

    protected void UploadButton_Click(object sender, EventArgs e)
    //=================================================
    // upload the file selected in the upload button to the library
    //
    //=================================================
    {
        string docLibName = "/documents/Forms/AllItems.aspx";

        if (FileUpload.HasFile)
        {
            try
            {
                int orderID = Convert.ToInt32(ViewState["OrderID"].ToString());
                string status = ddlDocumentStatus.SelectedValue;
                string docType = ddlDocumentType.SelectedValue;

                // Read the file contents into a byte stream
                string filename = FileUpload.FileName;
                byte[] contents = new byte[FileUpload.FileContent.Length];
                System.IO.Stream myStream;
                int fileLen = FileUpload.PostedFile.ContentLength;
                myStream = FileUpload.FileContent;
                myStream.Read(contents, 0, fileLen);

                // Upload the file to "Documents" Library
                using (SPSite oSite = new SPSite(_siteURL))
                using (SPWeb oWeb = oSite.OpenWeb())
                {
                    docLibName = _siteURL + docLibName;

                    SPWeb site = new SPSite(docLibName).OpenWeb();

                    // Copy the file to the sharepoint library
                    SPFolder myLibrary = oWeb.Folders["Documents"];

                    // try checking out the file, if it doesn't exist, create it:
                    SPFile spfile = null;

                    try
                    {
                        spfile = oWeb.GetFile(_siteURL + "/Documents/" + filename);

                        if (spfile.Exists)
                        {
                            spfile.CheckOut();
                            myLibrary.Files.Add(filename, myStream, true);
                        }
                        else  // create a new document
                        {
                            spfile = myLibrary.Files.Add(filename, myStream, true);
                        }

                        SPListItem document = spfile.Item;
                        // Copy the metadata to the document 
                        //spfile.Item;

                        // update the metadata for the document here

                        document["Columns Name"] = some_string_value;
                        document["Document Type"] = docType;

                        myLibrary.Update();
                        document.Update();
                        spfile.CheckIn("Document updated on " + DateTime.Today.ToString());
                    }
                    catch (Exception ex)
                    {
                        string errorMessage = ex.Message;
                    }

                    // update the sharepoint list
                    SPList docLib = oWeb.Lists["Documents"];
                    AddDocuments(orderID, docLib);
                    lblDocumentMessage.Text = "Document uploaded!";
                }// using - Disposes Site and web
            }// try
            catch (Exception ex)
            {
                string errorMessage = ex.Message;
                lblDocumentMessage.Text = "Document upload error: " + errorMessage;
            }
        }
    }

你想把文件放在哪里?你正在上传文件吗?