I have the following code in a web part which does the job to pull the information from the external website and create an XML file as data source to a datalist web control. This Data list should be displayed in the webpart. For some reason, I can not see any information if I use this in the web part. Please guide me how to fix this problem.

string sJobURL = "http://www.example.com/extsearch/?client_id=123034&infonly=1&quick_search=0&show_desc=Y";
        string sInternalJobURL = "http://www.example.com/extsearch/?client_id=123034&infonly=1&quick_search=0&show_desc=Y";
        string sJobsPath = @"C:\app\jobs.xml";
        string sInternalJobsPath = @"C:\app\internaljobs.xml";
        string sProcessed = @"C:\app\Alljobs.xml";
        string sRootElementName = "vacancy_details";
        string sUniqueKeyName = "id";

        XmlDocument xml = new XmlDocument();


        XmlDocument doc = new XmlDocument();
        var result = doc.DocumentElement.GetElementsByTagName(sRootElementName)[0] as XmlElement;
        Merge(sInternalJobsPath, doc, result, sProcessed, sRootElementName);

        DataSet ds = new DataSet();
        XDocument xdoc = XDocument.Load(sProcessed);
        var query = xdoc.Descendants(sRootElementName).Select(data => data.Element(sUniqueKeyName).Value).Distinct();

        if (ds.Tables.Count > 0)
            datalist.DataSource = ds.Tables[sRootElementName].DefaultView;
  • Version of SharePoint? Is this a visual web part? Try running debugger and confirm your ds.tables.count is in fact greater than 0. – David Lozzi May 29 '13 at 13:09
  • it is sharepoint 2010 and it is a visual web part. I am not sure if I can run this code as it is. I have not created any Sharepoint list by using BCS. – Ram May 29 '13 at 13:19
  • Where is this code? OnLoad? PreRender? OnInit? – Neil White May 29 '13 at 13:45
  • You shouldn't need BCS, as you're calling a service directly in code. – David Lozzi May 29 '13 at 13:50
  • I am using this code in oninit. – Ram May 30 '13 at 8:38

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.