Friday, October 28, 2011
Programmatically add web part on page layout
Wednesday, July 27, 2011
GAC issue during WSP deployment
Some times when we deployed WSP by bat file we get this type of issue, I was very unhappy when I saw this error and unable to find out why it is coming
to resolve it go to assembly and remove all install related DLLs and if some dll denies to uninstall go to process(task manager) and stop all SharePoint /visual studio related process.
Thursday, July 14, 2011
Good reference for SharePoint learning(NO code solution)
hi guys I found a link to understand SharePoint and most important it is Video hurrrreeeeeeeeeeyyyyyyyyyyyyy
http://www.sharepoint-videos.com/all-free-videos/
I think you like it
Thursday, July 7, 2011
Timer job in SharePoint
Hi guys in previous days I got chance to work on Timer job ,scenario was that “my timer job call a wcf service and after do some calculation it will update SharePoint custom list”
I follow Andrew connell' and other blogs and come to know few things
A. SPWebApplication webApplication = this.Parent as SPWebApplication;
SPContentDatabase contentDb = webApplication.ContentDatabase[contentDbId];
please never forget to add this in your custom timer job.
B.you cant active timer job by UI
c.And it is very hard to debug timer job.so need to keep patience.
In coming post I will try to put my way to accomplish this task.
Thursday, June 16, 2011
Error when retract solution from SharePoint Administrator
When We try to retract solution from central administrator sometimes we see below error page and try to retract from sts command ….
There is another way go to services and check SharePoint administrator service and restart it now go back to site and cancel retract and again retract it see it is working ![]()
Paging And Sorting In SharePoint Webpart with Custom User Controls
HI, Friends in last couple of days I worked on Paging and Sorting on Webpart,
Several times we need to implement Sorting and Paging IN SharePoint Webpart. To accomplish this we have two ways
A) JavaScript(JQUERY) B)C# code
Because I think when we deploy our custom Webpart, it is easy to deploy same type of file with WSP so I choose B (what I want, just pass value (to its property) and it return paging nothing else so I could add it with any webpart)
My way to accomplish this
First i have a Webpart where all my data is coming from Database in descent way.
Now what i want, i want Show data in paging format and data row could be change from user end so Custom property are the best way so I create a Custom property in my Webpart
[WebBrowsable(true),
WebDisplayName("Records per Page"),
WebDescription("Records per Page"),
Personalizable(PersonalizationScope.Shared),
Category("Spigit Settings")]
public int RecordsPerPage { get; set; }
Now what i have=> Total number of record & Record par page
TO pass default Value, Add this in CreateChildControls
if (RecordsPerPage == 0)
RecordsPerPage = 10(or whatever you want)
We have to fetch Total number of record in difftent variable( this will use in User control to caluculate total page) But keep in mind i will fetch only those record that i m showing
Because I use Entity framework so I used skip and Take method
So your method could be seeing like this
memberList = userController.Users(memberSortField, (RecordsPerPage * (currentPageNumber - 1)), RecordsPerPage);
currentPageNumber =>check current page number
if (Page.Request.QueryString["Page"] != null){
int pageNumber = 0;
if (int.TryParse(Page.Request.QueryString["Page"], out pageNumber))
{
return pageNumber;
}
}
return 1;
memberSortField=>this is use for sorting parameter
We have now all things
Now move to Create UserContol to show Paging
public class PagingUserControl : UserControl
{
public int PageSize { get; set; }
public int TotalRecords { get; set; }
public int PageNumber { get; set; }
LinkButton butPrevious;
LinkButton butNext;
protected override void CreateChildControls()
{
base.CreateChildControls();
butPrevious = new LinkButton();
butPrevious.Text = "Prev";
butPrevious.Click += new EventHandler(butPrevious_Click);
butNext = new LinkButton();
butNext.Text = "Next";
butNext.Click += new EventHandler(butNext_Click);
int pageCount = 0;
HtmlGenericControl genericControl1 = new HtmlGenericControl("div");
genericControl1.Attributes.Add("class", "paging-items");
this.Controls.Add(genericControl1);
HtmlGenericControl genericControl4 = new HtmlGenericControl("span");
genericControl4.Attributes.Add("class", "td");
genericControl4.Controls.Add(butNext);
genericControl1.Controls.Add(genericControl4);
pageCount = GetPageCount(PageSize, TotalRecords);
for (int count = pageCount; count >0 ; count--)
{
HtmlGenericControl genericControl3 = new HtmlGenericControl("span");
string pageStatus = Page.Request.QueryString["Page"];
if (pageStatus != null && int.Parse(pageStatus) == count)
{genericControl3.Attributes.Add("class", "td selected");}
else
{
if (pageStatus == null && count == 1)
{genericControl3.Attributes.Add("class", "td selected");}
else
{genericControl3.Attributes.Add("class", "td");}
}
genericControl3.Controls.Add(new HyperLink { Text = count.ToString(), NavigateUrl = GetPageUrl(count) });
genericControl1.Controls.Add(genericControl3);
}
HtmlGenericControl genericControl2 = new HtmlGenericControl("span");
genericControl2.Attributes.Add("class", "td");
genericControl2.Controls.Add(butPrevious);
genericControl1.Controls.Add(genericControl2);
HtmlGenericControl genericControl5 = new HtmlGenericControl("div");
genericControl5.Attributes.Add("class", "em");
genericControl1.Controls.Add(genericControl5);
if (PageNumber == 1)
{
butPrevious.Visible = false;
}
else if (PageNumber == pageCount)
{
butNext.Visible = false;
}
if (TotalRecords <= PageSize)
{
butNext.Visible = false;
butPrevious.Visible = false;
}
}
void butNext_Click(object sender, EventArgs e)
{
Response.Redirect(GetPageUrl(++PageNumber));
}
void butPrevious_Click(object sender, EventArgs e)
{
Response.Redirect(GetPageUrl(--PageNumber));
}
private string GetPageUrl(int currentPageNumber)
{
string pageUrl = Page.Request.Url.ToString();
if (pageUrl.IndexOf("?") > 0)
{
string startUrl = pageUrl.Remove(pageUrl.IndexOf('?'), pageUrl.Length - pageUrl.IndexOf('?'));
if (pageUrl.Contains("&"))
{
string endUrl = pageUrl.Remove(0, pageUrl.IndexOf('&'));
pageUrl = startUrl + "?Page=" + currentPageNumber + endUrl;
}
else if (pageUrl.Contains("?SortBy"))
{
pageUrl = startUrl + "?Page=" + currentPageNumber +"&SortBy=" + Page.Request.QueryString["SortBy"];
}
else
{
pageUrl = pageUrl.Remove(pageUrl.IndexOf('?'), pageUrl.Length - pageUrl.IndexOf('?')) + "?Page=" + currentPageNumber;
}
}
else
{
pageUrl += "?Page=" + currentPageNumber;
}
return pageUrl;
}
private int GetPageCount(int recordsPerPage, int totalRecords)
{
int pageCount = 0;
if (totalRecords <= recordsPerPage)
{
pageCount = 1;
}
else
{
pageCount = totalRecords / recordsPerPage;
if (totalRecords % recordsPerPage != 0)
pageCount++;
}
return pageCount;
}
}
Now you have two property here, create a object of this control in Webpart and pass Value like this
PagingUserControl userControl = new PagingUserControl();
userControl.PageSize = RecordsPerPage;
userControl.PageNumber = currentPageNumber;
userControl.TotalRecords = pass Variable HERE
Add this control where u want tin webpart and all are working
I like to Thanks JOMIT (My Manager) he help me to make it dynamic .
In next Post we will add Sorting feature in this Webpart
