Showing posts with label SharePoint 2010. Show all posts
Showing posts with label SharePoint 2010. Show all posts

Monday, November 12, 2012

How to disable client side validation in sharepoint 2010

The validation controls are used get the right input from users.so i have used four validation controls for four text boxes in my web part.Then i was disable those validation based on page mode on server side.If the mode is display mode i will turn on all the validations on site.To turn on the validations we have to set the EnableClientScript property to false
WebPartManager wpmr = WebPartManager.GetCurrentWebPartManager(Page);
Respose.Write(wpmr.DisplayMode);
if (wpmr.DisplayMode == WebPartManager.EditDisplayMode)
{
ReOrderName.EnableClientScript = false;
RaOrderQuantity.EnableClientScript = false;
ReOrderAmt.EnableClientScript = false;
RaOrderAmt.EnableClientScript = false;
}
else if(wpmr.DisplayMode == WebPartManager.DesignDisplayMode)
{
ReOrderName.EnableClientScript = True;
ReOrderAmt.EnableClientScript = True;
}

Monday, October 15, 2012

How to add external script(JS) on page in sharepoint 2010

Here i will explain how to import the external java script file into specified share point site web page.To add the file reference by using  a class "script link" which will be used to request scripts by the time of page rendered in share point 2010.We will add the reference both client side and sever side to page using this below piece of code.
Client Side:
<SharePoint:ScriptLink ID="sl" name="/_layouts/Jscripts/testadd.js" runat="server" Defer="false"/>
Server Side:
By using the below method we can access script on server side.The Register method contains the there variable which are page name,script file name and localizable value .
ScriptLink.Register(this.Page, "/_layouts/Jscripts/testadd.js", false);

 

Friday, October 12, 2012

How to read XML file data in sharepoint 2010

 
In this post i have given code for how to read  the XML file data which in document library .Here i instantiated a Web Request object by using the path(URI) of the XML file ,then get the Response from path using Web Response class.The GetResponseStream method  is used to get the stream of  content in XML file to stream.Finally we will read the stream into resultant string.By doing the same process we can access any external XML file(URI) into application.But we have to use HttpwebRequest class to make request.
String file_path = "http://sp12/test"
WebRequest wr = WebRequest.Create(file_path);
wr.Credentials = CredentialCache.DefaultCredentials;
WebResponse Wresponse = wr.GetResponse();
using (StreamReader str = new StreamReader(Wresponse.GetResponseStream()))
{
String Result_Data =str.ReadToEnd();
}
Response.Close();

Monday, October 8, 2012

Get current user Profile in SharePoint 2010

Earlier i have given a customised solution to get the current user permissions in share point 2010.Here i will show how to get the user details from share point site using  UserProfileManager class.Before going to get the profile details we need to check whether the user is valid or not.Then the resultant data will be assigned to user profile class and get account name into string

SPSite sps = SPContext.Current.Site;
using (SPWeb spw = sps.OpenWeb())
{
SPServiceContext spsc = SPServiceContext.GetContext(sps);
UserProfileManager uprofile = new UserProfileManager(spsc);
string useraccountname = SPContext.Current.Web.CurrentUser.LoginName;
if (uprofile.UserExists(useraccountname))
{
UserProfile Profileinfo = uprofile.GetUserProfile(useraccountname);
if (!string.IsNullOrEmpty(Profileinfo["FirstName"].ToString()))
{
string AccountName = userProfile["FirstName"].ToString();
}
}
}

Friday, October 5, 2012

How read data from List in sharepoint 2010

In previous posts i have given how to read data from the excel file in document library.Here i have given a customised code to read the data from share point list. In the below code we are first get the data(ordername,orderamount,orderarea) from "orders" list using QAMLquery .Then the resultant data in to list item collection and read the each values through loop condition
SPList spl =SPContext.Current.Web.Lists.TryGetList("Orders");
SPQuery spq = new SPQuery();
spq.ViewFields =string.Concat("<FieldRef Name='OrderName' />","<FieldRef Name='OrderAmount' />","<FieldRef Name='OrderArea' />");
SPListItemCollection splc = spl.GetItems(spq);
foreach(SPListItem sitem in splc){
if(sitem != null)
{
Oname = item["OrderName"].ToString(); 
Oamt = item["OrderAmount"];
Oarea = item["OrderArea"];
}

I have used condition to check whether the list item(sitem) is null or not.Because the variables (oname and etc) has used in another method  here .

Monday, October 1, 2012

How to add images/files to document library in sharepoint 2010

In previous post we have seen how to get the updated items from the document library and read the excel file data from document library.Here i will shown how to add the image files to document library/List .For this i have been converted  the attachment file to string format then get the size using some length and memory of this.Then using document  library class the result Data has added to library after check in .
XPathNavigator dX = MainDataSource.CreateNavigator();
XPathNavigator XN = fileAttach.Current;
byte[] converted_attachment = Convert.FromBase64String(XN.ToString());
double filelength= converted_attachment.Length;
double memoryb = 2048 * 2048;
double resultfSize = filelength / memoryb;
if (resultfSize < 8 && resultfSize != 0)
{
int fln = converted_attachement[32] * 2;
byte[] fb = new byte[fln];
for (int i = 0; i < fb.Length; i++)
{
fb[i] = converted_attachement[24 + i];
}
string[] filenameparameter = System.Text.UnicodeEncoding.Unicode.GetChars(fb);
string ResultfName = new string(Filenameparameter);                            
byte[] Result_Data = new byte[converted_attachement.Length - (24 + fln)];
for (int i = 0; i < Result_Data.Length; i++)
{
Result_Data[i] = converted_attachement[24 + fln + i];
}
}
SPDocumentLibrary dl = (SPDocumentLibrary)Web.GetList(Site.ServerRelativeUrl + "/DesiredLibraryName");
SPFolder spfolder = dl.RootFolder;
SPFileCollection spf = spfolder.Files;
SPFile sf = spf.Add(spfolder.Url + "/" + DateTime.Now, Result_Data);
SPListItem spf_item = sf.Item;
spfitem["Filename"] = resultfName;
spfitem.Update();
spfitem.File.CheckIn("WF CheckIn", SPCheckinType.MajorCheckIn);


Monday, September 24, 2012

how to Passing parameters into a Modal Dialog Window in sharepoin 2010

The share point provide a class for crating modal dialog box i:e SP.UI.ModalDialog.Here i have given an example to create a dialog box for account result by using parameters.The parameter will be assign using args property

function ResultDialog() {
var options = {url: 'Account/Reports.aspx', autoSize: true,title:' 
args: { amt: 'Amt_Tot', category: 'sales' },dialogReturnValueCallback: Result
};
SP.UI.ModalDialog.showModalDialog(options);

}
For the above model dialog box i passed two arguments to display the sales amount regarding order.The reports.aspx has hold the resultant output ,so i dialog box url set to this page here.

Saturday, August 25, 2012

How to create Profile programmatically in sharepoint 2010

In this post i will given a code to create profile in share point 2010 .Here i have used Userprofilemanager class to do this.Then using this i will check the the whether the user name is exist or not.If it is not exit ,it will create as user profile
using (SPSite sc = new SPSite(SPContext.Current.Site.Url))
{
SPServiceContext c = SPServiceContext.GetContext(sc);
UserProfileManager upm = new UserProfileManager(c);
SPUser su = sc.RootWeb.CurrentUser;
if (!upm.UserExists(su.LoginName))
{
upm.CreateUserProfile(su.LoginName);
}
}

Tuesday, August 14, 2012

How to Get and check the application key values in web.config of Sharepoint site

In asp.net it is easy to access key values from web.config file using configuration assembly.Here in this post I will given an example to check whether the key value is exists or not for SharePoint site.The SharePoint provides  a class "webconfigurationManager" to access the key values from web.config file.Using the below bool method I will check the key value
 public static bool checkkeyvalues()
 {
using (SPSite sw = new SPSite(URL))
 {
 System.Configuration.Configuration cfig = WebConfigurationManager.OpenWebConfiguration("/", Sw.WebApplication.Name);
  AppSettingsSection aps = cfig.AppSettings;
return aps.ElementInformation.IsPresent;
 }
}

Wednesday, August 8, 2012

Get the data of updated items fom document library in sharepoint

In this post i will given a query to get the last updated items in Document library in share point 2010.We can do this task in two ways.One is using ViewXML property and other one is using  query property.The main difference between query and ViewXML is "The view XML contains view fields,Query etc but the query does not".Here i used ViewXml property  to define the query.

SPQuery resque = new SPQuery();
resque.ViewXml = "<View><Query><OrderBy><FieldRef Name='Modified'/></OrderBy></Query><RowLimit>50</RowLimit></View>";

Saturday, August 4, 2012

How to add column/Field to default view using powershell

In this post i will given different ways to add field to view using power shell in share point 2010 site.The first one is the basic process to add the field using power shell.In the second and final process we are used GetViewFromUrl method and splist object to add the field to view in SharePoint site .
$view=$list.views["GetAllItems"]
$view.viewfields.add($list.fields["customer"])
$view.update()
using GetViewFromUrl
$spsWeb = Get-SPWeb -Identity "http://orderssite"
$spsView = $spsWeb.GetViewFromUrl("/Lists/OrderList/GetAllItems.aspx")
$spItemField = $spList.Fields["customer"]
$spsView.ViewFields.Add($spItemField)
$spsView.Update()
Using SPList object
$spsList = Get-SPList -Url "http://orderssite/Lists/OrderList"
$spsView = $spsList.Views["GetAllItems"]
$spItemsField = $spsList.Fields["customer"]
$spsView.ViewFields.Add($spItemsField)
$spsView.Update()

Thursday, July 26, 2012

How to Delete UserCustomAction for List in sharepoint 2010

In this post i will explain how to delete the custom action of user for list.By using action collection we can get all the user action events on the list.Then we will go through the all items in this collection up to get the desired location.Finally we can set the new location to action then update the list
SPUserCustomActionCollection cAct = orderlist.UserCustomActions;
foreach (SPUserCustomAction act in cAct)
{
//Microsoft.SharePoint.ListEdit ::By using this we can set the location property for list
if (act.Name.Equals("orders") && act.Location.Equals("Microsoft.SharePoint.ListEdit"))
{
act.Location = "test";
act.Update();
orderlist.Update();
break;
}

Tuesday, July 24, 2012

sharepoint 2013 tutorial and download

Recently share point 2013(beta) has been released with new features.The complete overview of version and features are explained briefly in the below links

1. share point 2013 tutorial
2. share point 2013 developer tutorial
3. Develop apps for share point 2013 tutorial
4. Building apps office
3. share point 2013 download

Monday, July 23, 2012

Export excel data to sharepoint list in sharepoint 2010

Here i will given a simple way to export the data to sharepoint list from excel file which is in documnet library in sharepoint.The data table"Exceldata" has used to get the excel data then bind this data to SPlist.Here first we get the path of the excel file in documnet library ,then using this path in connection string.
string ExcelfileName = Path.GetFileName("http://url/Test.xls");
string ExcelileLocation = Server.MapPath(Excelfilename);                
String Con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ ExcelfileLocation +;Extended Properties=Excel 8.0;";  
OleDbConnection objCn = new OleDbConnection(con);  
DataTable ExcelData= new DataTable();
oleDbDataAdapter Oda = new OleDbDataAdapter("select * from[Sheet1$]", Con);   
oda.Fill(ExcelData); 
SPList ExcelDataList = w.Lists["ExcelDataList"];
for (int j = 0; j <= ExcelData.Rows.Count - 1; j++)
{
SPListItem ExcelDataistItem = ExcelDataList.Items.Add();
for (int i = 0; i <= ExcelData.Columns.Count - 1; i++)
{
string ColName = ExcelData.Rows[0][i].ToString();
ExcelDataistItem[ColName] = ExcelData.Rows[j][i].ToString();
}
ExcelDataistItem.Update();      

Monday, July 2, 2012

Complete details about linq in sharepoint

what is LINQ?
LINQ Stands for Language Integrated Query , which  is used by the .net developers to query and transform the data .LINQ is a new data access paradigm,which allows the users to use SQL like Syntax in various data sources through out the application .
What is the main uses of LINQ?
By Allowing  the backend data resources to decide which way is the best to resolve the query , LINQ can improve the performace of the application .Now with sharepoint supporting the LINQ ,its makes query information for the platform easy through LINQ Query Listing in a condensed and easy format .
what are the fetaures of linq in sharepoint?
1) LINQ processes its queries through Custom Query provider that translaters LINQ quries through CAML ,which is a Collaborative Application Markup language which is later on used by the Sharepoint.
2)LINQ also extends its support in C# 3.0 and Visual Basic 9.0 .Visual Studio Integration for the Entity Creation is also known as SPML .
3)Entity Creation tool SpMetal to export SharePoint List definations to entity Classes used for querying .
4) LINQ can be connected to Sharepoint via ,Sharepoint Object model or through Sharepoint Web Services .
5) LINQ also provides the extended support to update through the entity Type.

Sunday, June 24, 2012

How to Read Excel File data from Document Library in sharepoint 2010

Here i will show how to reading the of excel file which is in Document library.The "url" is the path of excel file in library .To do the excel application process we have to add the Microsoft.Interop.Excel.dll.Then get the data form the file and transfer to values.
ApplicationClass Mexcel = new ApplicationClass();
string wbPath = url;
Workbook Workbook = Mexcel.Workbooks.Open(wbPath, 0, false, 5, "", "", false, XlPlatform.xlWindows, "\t", true, false, 0, true, 0, 1);
Sheets ss = Workbook.Worksheets;
Worksheet ws = (Worksheet)sts.get_Item(1);
for (int i = 1; i <= ws.Rows.Count; i++)
{
 Range rn= worksheet.get_Range("C" + i.ToString(), "F" + i.ToString());
 var values = (System.Array)range.Cells.Value2;
}

Tuesday, June 19, 2012

Silverlight Client Object Model in SharePoint 2010

Silver light Object model is introduced in Microsoft SharePoint 2010 along with ECMASCRIPT and managed Client side model .Silver Light Object model supports its implementations in three possible contexts .

1) Within the silver light web part applications .
2) With in the silver light cross domain data access system .
3)Modifying the  Client Access cross domain policy ( High Security risk and not supported by Share Point Foundation )
                                Since the query execution is asynchronous when you use the SharePoint Foundation Silverlight object model, you must pass delegates for callback methods as parameters in the ExecuteQueryAsync(ClientRequestSucceededEventHandler, ClientRequestFailedEventHandler) method, similarly to query execution in the JavaScript object model.
                                 However ,in order to make changes in the User Interface through silver light object model ,you must delegate this work to the Dispatcher object of the thread that created the UI by calling Begin Invoke method .

Monday, June 18, 2012

JavaScript Client object model in SharePoint 2010

ECMASCRIPT(JavaScript or Jscript )client  object model  is introduced in Microsoft SharePoint 2010 along with Silverlight and managed client object models. The JavaScript Object models will let you work on the objects without deploying the code on the server .This helps the application with reduced stress of server and bound to easy loading of the application .
                                  
                                     This type of models efficiently run for sandbox solutions and server side hierarchy applications. Since Java Script works on the Client context ,that is it works just for the current context there is no scope for the object availability for cross site scripting or the access of the object model away from the current context ,which will enhance the already existing security feature of the application . to reduce the stress on the server ,this client object model doesn't load all the object properties when a object is created .  
                                       
                                    The Data retrieval is done on client load function using the methods like set_ and get_ based on the availability to retrieve or set the value of the property. The JavaScript Class Library contains the reference material and properties for the objects .Due to lots of similarities in managed object model and java script object model .They both share the similar Orientation .

Thursday, June 14, 2012

How to hide and show the fileds or controls in sharepoint 2010

Here i wanna show how to hide the control in editable form in share point at server side.Here i have requirement to show the salesperson name and hide the salesperson id when the form in edit mode.For this there is pretty simple property used in share point to hide controls or Field i:e ShowInEditForm.I just set the property to true for salesperson name field to show and false for id field to hide
SPSite ss = new SPSite(url)
SPWeb sw = ss.OpenWeb())
SPList slist = sw.Lists["Orders"];  
SPField salespname = slist.Fields["salesPerson"];
SPField salesid = slist.Fields["SID"];
//show the salesperson name field in edit mode   
salespname.ShowInEditForm = true;
//to hide the sales person field in edit mode  
salesid.ShowInEditForm = false;  
salesid.Update(); 
salespname.Update();

Saturday, June 9, 2012

How to hide view in SharePoint 2010

Here I will hide the one of view which get from the existing List in SharePoint. India_orders is the view ,get from the orders list then hide ursing hidden property of view
SPsite ss = SPcontext.Current.Site;
Spweb sw = SPContext.Current.Web;
SPList sl = sw.Lists["Order"];
SPView Indview = sl.Views["India_orders"];
Indview.Hidden = true;
Indview.Update();
Console.Writeline("Hide the desired View");

Bel