2013-03-12 46 views
0

我有以編程方式創建發佈網站的代碼。除了一件事以外,它工作正常。我必須將out of box文檔listview web部件添加到default.aspx頁面。它添加了Web部件,但它沒有在底部添加文檔鏈接,就像您手動添加文檔Web部件時所看到的那樣。奇怪的是,如果我編輯Web部件,有列表視圖,外觀,佈局和高級部分。我點擊確定而不做任何更改,如果我回去編輯Web部件,則會添加2個部分。 AJAX選項和雜項。如果我再次單擊確定而不進行更改,則會顯示添加文檔鏈接。問題將文檔庫web部件添加到sharepoint頁面

string pageURL = "default.aspx"; 

SPFile destFile = newWeb.GetFile(pageURL); 
if (destFile.Exists) 
{ 
    if (destFile.CheckOutType == SPFile.SPCheckOutType.None) 
    destFile.CheckOut(); 
} 
else 
{ 
    pageURL = "pages/default.aspx"; 
    destFile = newWeb.GetFile(pageURL); 
    if (destFile.CheckOutType == SPFile.SPCheckOutType.None) 
     destFile.CheckOut(); 
} 

SPLimitedWebPartManager mgr = 
    newWeb.GetLimitedWebPartManager(pageURL, PersonalizationScope.Shared); 

// add the document library 
SPList docLib; 

if (!bHasDocuments) 
{ 
    // create the document library 
    Guid docLibGuid = newWeb.Lists.Add(
     "Documents", 
     "", 
     SPListTemplateType.DocumentLibrary); 

    docLib = newWeb.Lists[docLibGuid]; 
} 
else 
{ 
    docLib = newWeb.Lists["Documents"]; 
} 

docLib.OnQuickLaunch = true; 
docLib.Update(); 

SPDocumentLibrary spDocLib = (SPDocumentLibrary)docLib; 
spDocLib.EnableVersioning = true; 
spDocLib.EnableMinorVersions = false; 

// add the doc lib to the home page 
ListViewWebPart wpDoc = new ListViewWebPart(); 
wpDoc.ZoneID = "TopZone"; 
wpDoc.ListName = docLib.ID.ToString("B").ToUpper(); 
wpDoc.ViewGuid = docLib.DefaultView.ID.ToString("B").ToUpper(); 

// Add the web part 
mgr.AddWebPart(wpDoc, wpDoc.ZoneID, 20); 

任何想法如何讓Web部件包含添加文檔鏈接?

回答

0

與 XsltListViewWebPart wpDoc嘗試=新XsltListViewWebPart();

INSTEAD of ListViewWebPart wpDoc = new ListViewWebPart();

它在SP2013中爲我工作。

相關問題