SharePointAds TextOnly

Thursday, 27 August 2009

Sharepoint: How to get MAX id of list?

How can we get MAX id of any present list?
-> Simplely use following code
(*Note: insert your list name rather ' List_Name ')

public string MaxListId()
{
SPWeb web = SPContext.Current.Web;
SPList oList = web.Lists[" List_Name "];
SPQuery query = new SPQuery();

query.Query = " ";
SPListItemCollection items = oList.GetItems(query);

DataTable dtmax = new DataTable();
dtmax = items.GetDataTable();

string maxId = "";
foreach (DataRow row in dtmax.Rows)
{
maxId = row["ID"].ToString();
break;
}

return maxId;
}


--

Sharepoint : How to redirect list form URL's?

We can redirect sharepoint's default New/Edit/display forms by our new created custom forms..

SPList list = web.Lists["listName"];
SPContentType ct = list.ContentTypes["Item"];

ct.NewFormUrl = "NewCustomForm.aspx";
ct.EditFormUrl = "NewEditForm.aspx";
ct.DisplayFormUrl = "NewDisplay.aspx";
ct.Update();

newVendorList.Update();


-

Sharepoint: Programatically add LookUp field to custom list

We can add programmatically other 'LookUp' field as a new column into custom list, simply add below code.. :)

SPList targetList = web.Lists["List1"];
list.Fields.AddLookup("Col2", targetList.ID, false);
SPFieldLookup lookupField = list.Fields["Col2"] as SPFieldLookup;
lookupField.LookupField = targetList.Fields[SPBuiltInFieldId.Title].InternalName;
lookupField.Update();

Suppose we have two different list List1 and List2, and in List1 have three columns as col1, col2, col3.
So with above code, it creates new lookup field as 'Col2' column in List2.


-

Friday, 21 August 2009

Sharepoint : Want to create new simple application site in sharepoint?

Just do following steps to create simple sharepoint new site with VS2008.

1. Create new sharepoint project, select "Empty" template, give name for your project
2. Now right click on your project, select 'Add'>New Item and select "Module" from sharepoint template, give name (keep in mind this is your feature name...)
3. It automatically creates Module.xml (you can called as element.xml) and sample.txt
4. Add custom pages or do any think what you want
5. Simply press F5, then automatically create solution, copy assemply to GAC, also create new feature folder in 12 hive, and deploy in your sharepoint site...


its soo simple :)

*Note: To add new sharepoint template in VS 2008, please WSS 3.0 extension for VS 2008.

Friday, 7 August 2009

.Net: Difference between String and Stringbuilder?

Usually, String is immutable type which means once you have the content there then you can't change it. While StringBuilder is mutable because it allows you to change the content that you have already placed.
Important to keep in mind that a string allows you to change the content but offcourse it always creates a new string reference. For example, all string methods return a new string and don't update the same string variable.
When you have huge amount of concatenation, best recommendation to go for StringBuilder!
Example:
String and StringBuilder class stores strings. But when you cannot change a String object after creating one.
eg: String name = "Test";
By saying you can't change the name object means you can't change the value in name object internally. When you change the name object value to something else, a new String object is creating in memory and assign the new value.

eg: name = "Test Example";

A new name object is creating in memory and the value "Test Example" is assinging to the newly created space.

But StringBuilder class occupies the same space even if you change the value.
If you are doing string concatenation StringBuilder class is far better in performance than String class.

You can use StringBuilder's Append() method to use concatenation.


also check this link Example