Datasources in SharePoint
Datasource is used in SharePointDesigner are 4 types. Those are
1.XML
2.Database
3.List
4.Webservice
Using datasource with XML File
Open SharePointDesigner2010 ---> click on Open site or Recent Sites -->
Give our site url --->
Select sitepages --->
Rightclick and create a new .aspx page --->
Create.
Right click on our new aspx file and select Edit file in Advanced mode --->
Insert -->
Table --->
Draw table as you required. Design the page.
From leftside navigation select 'Datasources' -->
From topmenu -- select 'XML File Connection' ---> Click on browse and choose where is our required xml file and select the file ---> OK.
It will asking you a dialog box that file want to move to our sitelocation. You should say yes. Now xml file will be in site collection.
Goto Our XMLDemopage and click on Insert menu--->
DataView --->
Select our xml file and click on OK.
* XML File will be added to our page in Data source details section at right side.
* Now you can select xml file or required columns from datasourcedetails and drag to the page.
* Now select the list and goto Datasoruce details
---> Select XML File
---> Insert Selected Fields as
---> choose your required option as below
1.Single item view : Displays each record in one page.
2.Multiple item view : This is bydefault option. All items in a page.
3.Single Item Form: Displays single item in one page as edit item mode.
4.Multiple Item Form: Displays all items in one page as edit item mode.
5.New Item Form : Displays as New item form mode with save option.
================================
2. Using Datasource - Database
SPD -->
SitePages -->
Createnewpage [dbsample.aspx] -->
open in Advanced mode -->
Design the form as you required -->
insert table --->
Now select Datasources navigation --->
click on 'Database Connection' in top menu --->
Click on 'Configure Database Connection' --->
Enter the sqlserver server name Ex: 'HANU-PC\SQLEXPRESS' and select the provider ---> Sqlserver/ oracle.
Give the authentication details --->
Select the Database from list --->
select the required tables and click on Finish.
* Now Datasource Properties dialog box opens. If you want any conditions like where then you select 'Filter' option to write the code.
* Filter --> select the field name, select the comparison, value, And / Or ....
* Sort ---> This option is used for sorting the table as selected column.
* Now check the Datasources page you will find newly created database connection under DatabaseConnections option.
*Now goto our dbsample.aspx page.
Insert -->
Dataview-->
Select our database connection--->
Table will be displayed in the page. Check at right side also.
*Select the table in the page --->
'Options' topmenu --->
'Inline Editing' Ribbon --->
Show Edit item links : For editing the record
---> Show Insert item links : For inserting new record
---> Show Delete item links : For deleting the record
---> Synchronize commands //default option
================================
3. Using Datasource - List
* Another type of datasource is List.
* Here we'll create a list and that list data will be using to newly created pages * Create a custom list in Browser or SPD
* Create required columns and Add some records to the list. [studentlist]
*Open SPD --->
Sitepages --->
New page --->
listdemo.aspx --->
Edit in Advanced Mode --->
Design the page with tables and make colorful. ---> Insert --->
Dataview --->
Select the list --->
List data is displays in listdemo.aspx page.
================================
4. Using Datasource - Webservice
** Webservice like a class library. Service.asmx file creates.
Open Visualstudio 2010 --->
File --->
New -->
website --->
Goto .NET Framework3.5 --->
ASP.NET WebService --->
Browse for our location ---> Filename ... OK
Open App_Code/Service.cs and write the follow code //Bydefault it is opens
Write the following code
[WebMethod]
public string HelloWorld() {
return "Hello World";
}
[WebMethod]
public int add(int a, int b)
{
return a + b;
}
[WebMethod]
public int subt(int a, int b)
{
return a - b;
}
public int mult(int a, int b)
{
return a * b;
}
---------------------------------------
* When you run [f5] this application http://localhost:3358/ws1/Service.asmx will be opens and you will found HelloWorld, add, subt methods and if you click these methods they will run and produce out put in xml format. But mult method have no [WebMethod] option so it could not be visible in service.asmx.
================================
Ex : 2
Add the namespaces :
using System.Data;
using System.Data.SqlClient;
write the code in webmethods as
[WebMethod]
public DataSet MyData( )
{
SqlConnection con=new SqlConnection("Data Source=Hanu-PC/SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=True");
string sql1="select * from emp";
SqlDataAdapter da=new SqlDataAdapter(sql1,con);
DataSet ds=new DataSet();
da.Fill(ds);
return ds;
}
Build and Run (F5) the Webservice.
Test the method, copy the URL.
*SPD --->
SitePages --->
Create a new page [webservicedemo.aspx] ---> Design --->
Datasources --->
In the ribbon click on SOAP Service connection service description location. Click on Connect now.
*In the operation select MyData ---> OK
* In the datasources you will find new section
(Soap Services) under that you will find your webservice.
---> Now in the page click on insert menu click on dataview, under soap services section
---> Click on your webservice.
It will be place in the page or from the datasource detail section. Select yours required columns click on insert selected field as dropdown, click on multiple view. It will desplayed on the page, save and close.
* ========= * ========= * ======== *