从sharepoint 2010文档库检索文档

从sharepoint 2010文档库检索文档,sharepoint,sharepoint-2010,Sharepoint,Sharepoint 2010,我正在将文档上载到文档库。除此之外,我还通过组合2个值创建了一个名为“FieldID”的字段。但是,我无法在文档库中看到此字段,因此无法使用此字段查询文档。如何查看此字段或如何使用此“FieldID”检索文档。这是代码 if (UploadFile.PostedFile != null || (UploadFile.PostedFile.ToString() != string.Empty)) { String fileNam

我正在将文档上载到文档库。除此之外,我还通过组合2个值创建了一个名为“FieldID”的字段。但是,我无法在文档库中看到此字段,因此无法使用此字段查询文档。如何查看此字段或如何使用此“FieldID”检索文档。这是代码

if (UploadFile.PostedFile != null || (UploadFile.PostedFile.ToString() != string.Empty))
{                               
    String fileName = UploadFile.PostedFile.FileName.ToString();                
    string userLogin = SPContext.Current.Web.CurrentUser.LoginName;                
    Guid siteID = SPContext.Current.Site.ID;
    SPDocumentLibrary exposureLibrary = null;
    SPList listDoc = null;
    SPFolder myLibrary = null;

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        using (SPSite oSite = new SPSite(siteID))
        {
            using (SPWeb oWeb = oSite.OpenWeb())
            {
                oWeb.AllowUnsafeUpdates = true;   
                // exposureLibrary
                try
                {
                   // Check if the document library already exists
                    exposureLibrary = (oWeb.Lists[SharepointCommon.Constants.USERINTERFACECUSTOMIZATIONSFEATURERECEIVER_EXPOSURE_DOCUMENTLIBRARY_NAME] as SPDocumentLibrary);

                    exposureLibrary.ContentTypesEnabled = false;
                    exposureLibrary.EnableAttachments = false;
                    exposureLibrary.EnableFolderCreation = false;
                    exposureLibrary.EnableVersioning = true;
                    exposureLibrary.NoCrawl = true;
                    exposureLibrary.OnQuickLaunch = false;
                    /* create a Text field for ID */


                    SPFieldText field = (exposureLibrary.Fields["FILEID"] as SPFieldText);

                // Check if the field is available
                    if (field == null)
                    {
                        SPFieldText fldID = (SPFieldText)exposureLibrary.Fields.CreateNewField(
                                        SPFieldType.Text.ToString(), "FILEID");
                        fldID.Required = true;
                        fldID.MaxLength = 100;
                        fldID.Hidden = false;
                        exposureLibrary.Fields.Add(fldID);
                    }
                    //exposureLibrary.Update();
                    myLibrary = exposureLibrary.RootFolder;

                }
                catch
                {

                    // Determine the GUID of the document library
                    Guid ExposureDocumentLibraryId = oWeb.Lists.Add(SharepointCommon.Constants.USERINTERFACECUSTOMIZATIONSFEATURERECEIVER_EXPOSURE_DOCUMENTLIBRARY_NAME, SharepointCommon.Constants.USERINTERFACECUSTOMIZATIONSFEATURERECEIVER_EXPOSURE_DOCUMENTLIBRARY_DESCRIPTION, SPListTemplateType.DocumentLibrary);

                    listDoc = oWeb.Lists[ExposureDocumentLibraryId];

                    /* create a Text field for ID */

                    SPFieldText fldID = (SPFieldText)listDoc.Fields.CreateNewField(
                                    SPFieldType.Text.ToString(), "FILEID");
                    fldID.Required = true;
                    fldID.MaxLength = 100;
                    fldID.Hidden = false;
                    listDoc.Fields.Add(fldID);

                    // Set properties of the document library
                    listDoc.ContentTypesEnabled = false;
                    listDoc.EnableAttachments = false;
                    listDoc.EnableFolderCreation = false;
                    listDoc.EnableVersioning = true;
                    listDoc.NoCrawl = true;
                    listDoc.OnQuickLaunch = false;                                
                    listDoc.Update();
                    myLibrary = listDoc.RootFolder;
                }


                // Prepare to upload
                Boolean replaceExistingFiles = true;


                // Upload document
                SPFile spfile = myLibrary.Files.Add(UploadFile.FileName + "(" + ViewState[UIConstants.CUSTOMERID].ToString() + " - "+ViewState[UIConstants.MondiPlantID].ToString()+ ")", UploadFile.FileContent, replaceExistingFiles);
                //spfile.Item["FILEID"]= ViewState[UIConstants.CUSTOMERID].ToString() + " _ " + ViewState[UIConstants.MondiPlantID].ToString();
                //myLibrary.Item["ID"] = ViewState[UIConstants.CUSTOMERID].ToString() + " _ " + ViewState[UIConstants.MondiPlantID].ToString();
                spfile.Item.Update();
                oWeb.AllowUnsafeUpdates = false;`enter code here`

                // Commit 
                myLibrary.Update();
                // Update the document library
                oWeb.Update();                           
            }
        }
    });    
}
exposureLibrary.Fields.Add(fldID)//在这一步之后

//exposureLibrary.Update()


您需要取消对此的注释,因为在try块中创建字段后,列表/库不会更新

任何进一步的帮助。我想根据某些条件从文档库中检索文档,并将它们显示为链接。单击链接时,应打开文档。谢谢你的帮助。。