Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

Show data from list by using web services through SharePoint designer

When working on big SharePoint projects we will get really good requirements and most of them are the challenging. In some cases we need to show the data by pulling from one list in a site to another site. For example, on “Site A” home page we want to show the data from another site or sub site. Then we need to use the web services and call the list and get the items. This is what this blog post is completely about.

How is it useful?

It is useful because as far as i know we have two ways of doing this without coding.

1. By using IFrames on the web pages. Create a content editor web part on the page of the site where you want to show the list content and add a IFrame and point it to the page where list data is present in another web site. So it is just doing nothing, just loading that page as it is. But it’s not a right way of implementing it. Because if authentication is different then you need to login to the site 2 times. One for the main site and another for the IFrame. Another problem is we can’t use IFrames on the web pages for security and performance issues. So it’s not a good way of doing. Then is there any other way?

2. Yes, We have a solution for this and it’s the better way of implementing it. Call a web services by connecting to the web services of the site we want to get the data, pass credentials and then select the list or library you want. Add a web part to the page and give the list we pulled from web service to the web part. That’s it. It is the easy and efficient way. I am explaining this a little bit detail below.

  • Create a SharePoint web part page for showing content by using web services.
  • Open the page in SharePoint designer and detach it from page layout.
  • Now, we need to add a web part for showing the data. We have a very comfortable and most usable web part in SharePoint nothing but Data View web part. Add this to the page.
  • Now, web part is ready and need of data source. So we need to go for list where we have to pull the data. It can be in the current site, sub site or some other site.        SharePoint_XML_Web_Services
  • Go to Task pane menu item of SharePoint designer and select the Data Source Library. Now you are able to see the all the data sources exist in the current site only. For example, if you want to pull data from a list which is in subsite or some other site you can’t find the data source entry in the lists and libraries section. This is the time where we need to go for XML web services. See above figure for more details.
  • Now we need to add a new XML web service data source to our site. How difficult it will be? very simple, follow below.
  • Expand the node XML web services and you can find the link called “Connect to a web service”.
  • Now you are open up with a window where you can see the properties of the web service data source.XML_web_services_Data_Source_PorpsNow we need to set the properties for the data source. Move to the tag General. Fill the name, description and keywords. 
  • Move to tab source and fill the source description location. You can browse to the location of the site and add the which asmx file you want to add. Or if you know location you can manually enter the url. Usually the location is like this. http://sharepointserver/_vti_bin/lists.asmx?WSDL
  • Remember for example purpose, i given the lists.asmx file path, you can use any of available web service.
  • Before click on Connect now button, check the credentials. You have options for entering credentials, or use default/windows credentials or don’t ask for credentials etc. Set the credentials type and then say Connect now.

Login_DataSource

  • Now the command to configure. Our case, we want to show the data. So it should be the Select operation.
  • Select the port : ListsSoap [default one]
  • Select operation type : GetListItems
  • Now time to pass parameters to the data source. First thing is you need to select the listname parameter that from which list you need to get the data.You can pass parameters to the web service to filter the results too.  For example, if your list has the boolean column for IsUpdated. Then we want to show only the columns which are having IsUpdated=false, then you can set that here. DataSource_ParametersWe are done with configuring and setting the data source properties.
  • We have data source ready and we need to use it to link to the data view web part.
  • If you set everything correct, then you can see the entry under the XML web service section.
  • Click on the data source and choose Show data from the menu.
  • Now, it will open Data Source Details task pane that pull all the column information from the list that you connected to as shown below.

DataSource_DetailsSelect the  list of columns that you want to show on the page. [You can select multiple columns by pressing the control key.]

  • Now click on the option “Insert selected fields as” Multiple Item view. It will add all the selected columns to the Dataview web part.
  • Save the page and view it in browser.

How nice it is, and how simple it is?

Really thanks to SharePoint designer and Data view web part that makes our work easier.

Please post comments if you have any questions.

Read More...

Read xml from web page and bind the data to Silverlight module.

Some times we have requirements in SharePoint that we need to pull images from SharePoint library and display those images in Silverlight module with rich UI. But we know that Silverlight runs on client side, we can't access the SharePoint libraries in the Silverlight projects because of permission issues as well.
So, here we build an architecture that SharePoint will build the XML for us and write it on the page and Silverlight grabs the XML from the page and displays the images on the UI. How nice it is. You can get the first part i.e. get xml (image) data from the SharePoint libraries here.

Here, we are discussing about the code we need to place in Page.xaml.cs file to read xml from web page.
public Page()
{
string controlid = "divImgs"; //You can also use intiparams of Silverlight params to get the id.
InitializeComponent();

string xmlstring = string.Empty;
if (controlid != null)
{
HtmlElement ctl = HtmlPage.Document.GetElementById(controlid);
if (ctl != null)
xmlstring = (string)ctl.GetProperty("innerHTML");
}

if (!string.IsNullOrEmpty(xmlstring))
{
ProcessXML(xmlstring);
}
}
The above code is the Page constructor of the Page. Xaml.cs file.
1. Here, we are catching the control on the HTML document and reading it's HTML. if you remember, while coverting the data view web part data from HTML to XML, in the XSLT i assigned an id for a html tag called "divImgs". We are using this id here in the cs file, and reading the HTML, obviously it will get the xml data to the xmlstring variable.
2. No, we need to process the XML and bind the data to the silverlight control. This is why i am calling a function called "Process XML".
private void ProcessXML(string xml)
{
images = new List<string>();
if (xml != string.Empty)
{
try
{
StringReader textStream = null;
textStream = new StringReader(xml);

if (textStream != null)
{
using (XmlReader reader = XmlReader.Create(textStream))
{
while (!reader.EOF)
{
if ((reader.IsStartElement()) && (reader.LocalName == "slides"))
{
if (reader.HasAttributes)
{
reader.MoveToAttribute("baseUrl");
}
}
else
{
if ((reader.LocalName == "slide") && (reader.HasAttributes))
{
reader.MoveToAttribute("imageUrl");
string imageName = reader.Value.ToLower();
if ((imageName.Contains(".jpg")
|| imageName.Contains(".png")))
images.Add(reader.Value);
}

}
reader.Read();
}
}
}
}
catch (Exception ex)
{
}
}
}
3. In the above code, images is the global variable of type List<string>. We are filling this object with the image urls by reading the xml string.
4. Now by calling the ProcessXML function, we are done with getting image urls. So we have collection of image urls, and use this object to give input as the Silverlight module controls and display on the UI.

Very simple and nice.
Happy coding!!! Read More...

Show images in Silverlight by reading images from SharePoint library

Hi,

Silverlight works on client side, so it's not possible to add SharePoint libraries in Silverlight project. But we have a way that we can access SharePoint data and show it up in Silverlight in SharePoint site.

We have a requirement where we need to pull data from the SharePoint libraries and lists and show the data in Silverlight. Here i will explain a scenario where we can pull the images from image library and show it in Silverlight.



Follow the steps below to do this.

Get data from SharePoint library and make it in the form of XML.

  1. Go to the page where we want to show the Silverlight module on the site or create a new page.
  2. Open the page in SharePoint designer.
  3. Add a data view web part to the page some where in web part zone.
  4. Select the data source library from Task Pane menu.
  5. Select the library/list from the data source library where your images are present.
  6. Click on the library and select Show Data.

  7. Select the columns, which refer the Title, Image Path etc you want to show in Silverlight from Data Source details task pane.
  8. Select the option Insert select fields as "Multiple item view". So now our data view web part is filled with the data. [If you want apply some properties like show images in asc order etc..]
  9. After selected the columns, apply a filter to get only images from the library/lists. we can do this by selecting the filters option from the data view web part.
  10. Here, select the image title or url column in the field name, in comparison select contains and here enter valid formats Silverlight allows in the value field.

  11. Save the page and open it in the browser [IE].
  12. Till now what we did is, we are getting the data from the SharePoint library/Lists and showing up it in the data view web part and it renders as a table.
  13. Now, we need to change the XSLT of the data view web part to get the table format of data as the XML format. We have XSLT, so we can easily do that.
  14. Add the below XSLT code to the data view web part by going to edit for the web part and modify settings --> XSL editor.
  15. Remove text in the editor and add this code.


  16. If you observe i am pulling some values from the data view and making xml.

  17. Now, when you save the web part and see the page, you can't see anything in the data view web part, because now your data is in the format of xml.
  18. You can see this by doing view source and search for "
  19. We are done with part 1 now. i.e. getting data from SharePoint library. Now we will move to second part.
Get XML from the page and give that as input to Silverlight module:

At this point, we got the xml i.e. xml is on the page, now we need to read the xml from the page in the silverlight project and display the images as we want by applying animations, styles etc..

You can see the part 2 here.





Read More...

Role of ItemMetadata.xml in Infopath forms [SharePoint workflow].

Introduction:

ItemMetadata.xml is the file used to store/transfer the data from one Infopath to another. The name of the file is case - sensitive.

For example, in a sharepoint workflow, there are 10 steps, in each step we are using infopath and we want send some information from one to the next infopath form, the information won't save any where. we need to tell explicitly to infopath to store in xml file. that is nothing but ItemMetadata.xml.

It acts as the secondary data source to the infopath.

To compensate for the possibility of schema differences between the task data and the form it only stores the schema instead of data.

Example schema is

<z:row xmlns:z="#RowsetSchema" ows_fieldname=""/>

Note: Every field name should be prefixed with ows

In programming, we can retrieve the data from info path using the property called ExtendedProperties.

afterProperties.ExtendedProperties["filedName"].ToString(); Read More...
Related Posts with Thumbnails
GiF Pictures, Images and Photos