Hi I have a visual webpart dropdown menu which populates all the folders name of the document library. When I run the webpart in debug mode, it populates all the folders correctly. After I deploy the webpart, If I drag and drop from the webpart gallery, the dropdown value does not get populated(just display emtpy dropdown). What am I doing wrong? Below is the code
Do I have to include doc library code inside the initializeControl()?
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
InitializeControl();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Guid webId = SPContext.Current.Web.ID;
Guid SiteId = SPContext.Current.Site.ID;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite oSite = new SPSite(SiteId))
{
using (SPWeb site = oSite.OpenWeb(webId))
{
GetDocLibraryFolder(site, "SharePointDocLibrary");
}
}
});
}
}
private void GetDocLibraryFolder(SPWeb oWeb, string Docl)
{
SPList doclibs = oWeb.Lists[Docl];
DropDownList1.Items.Add("");
foreach (SPListItem myItemfolder in doclibs.Folders)
{
if (mycondition == value)
{
DropDownList1.Items.Add(myItemfolder.Name);
}
}
}
Many thanks in advance for suggestion or rearrange the code.