Wednesday, August 5, 2009

Steps to remove Projects from Recent Projects in Visual Studio Start Page

To remove the Projects from Recent Projects in Visual Studio, there is no direct option to do this.We need to go to Registry Editor and Remove the Projects,follow the steps as shown below.
1) Go to Run in the start menu, type regedit
.
2) Go to HKEY_CURRENT_USER --> Softwares --> Microsoft --> VisualStudio --> 8.0 (if we want remove the recent projects in VS2005) or 9.0 (for vs2008) --> ProjectMRUList
3) Select and delete the Projects, which we don't want to show in the Recent Projects List of VS2005 or VS2008.

Next time when you start Visual Studio, the removed project through registry editor will not be listed on the start page.

Monday, August 3, 2009

C# Code to Update Document in SharePoint Document library

SPSite mySite =null;
SPWeb myWeb =null;

/* represents the current site */

using (mySite = SPContext.Current.Site)
{
using (myWeb = mySite.OpenWeb())
{

/* Modifes Windows SharePoint Services data in some way, you may need to allow unsafe updates on the Web site, without requiring a security validation. */

myWeb.AllowUnsafeUpdates = true;
Guid listId = new Guid(listID);
SPList documentLibrary = myWeb.Lists[listId];
SPListItem document = documentLibrary.GetItemById(itemID);

SPFolder oFolder = documentLibrary.RootFolder;

SPFileCollection collFiles = oFolder.Files;
SPFile oFile = null;

/* overwrite the file if exists in the document library */

oFile = collFiles.Add(document.Url, bytes, true);

SPListItem listItem = oFile.Item;

listItem["Col1"] = Value1;
listItem["Col2"] = Value2;

/* updates the versionsing of the document library also*/
listItem.UpdateOverwriteVersion();

myWeb.AllowUnsafeUpdates = false;
myWeb.Dispose();

}
}

Wednesday, July 15, 2009

Get QueryString Data using javascript

Assume the url is "http://localhost:portnumber/site/pages/page.aspx?Id=1

javascript function:

function getQueryProjectNum(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++)
{
var pair = vars[i].split("=");
if (pair[0] == variable)
{
return pair[1];
}
}
}

var Id= getQueryProjectNum("Id");

Friday, July 10, 2009

C# Code to identify the Mobile Device

Mobile Device:

Request.Browser["IsMobileDevice"] == "true";

BlackBerry:


Request.Browser["BlackBerry"] == "true" ;

iphone:

Request.UserAgent.ToLower().Contains("iphone");

Sample c# code:

if (Request.Headers["User-Agent"] != null && (Request.Browser["IsMobileDevice"] == "true" || Request.Browser["BlackBerry"] == "true" || Request.UserAgent.ToUpper().Contains("MIDP") || Request.UserAgent.ToUpper().Contains("CLDC")) || Request.UserAgent.ToLower().Contains("iphone"))
{
Response.Redirect("www.google.com");
}

Thursday, July 9, 2009

Render sites in mobile device with required view

1) By default, all the sites are designed with the width 980 pixels.
2) If we render the page with this width in the mobile, the user sees your page with miniscule, illegible letters and must zoom in to see the interesting parts, this is unacceptable.
3) Luckily, there is an option for us.
Just we need to use a small "meta" tag as shown below.

<meta name="viewport" content="width=device-width,user-scalable=yes" />

width = device-width (automatically adjust according the device width or else you can give your required width)
initial-scale = represents the Zoom level at which the user initially wants to see the page.
user-scalable = if the content exceeds the page, it represents wheather to show the scroll bar or not.

Stylesheet:

If you are providing any style sheet, we need to add the "media" property as shown below.

<link rel="stylesheet" href="StyleSheet.css" media="screen" type="text/css">




Render SharePoint List Items in ObjectList Mobile Controls

Generally, we use repeater control or datalist control to bind the SharePoint List Items.
When comes to Mobile Controls we use ObjectList Controls which works as repeater control.

Below is the sample code shows the procedure to bind the SharePoint List Items to ObjectList Control.

//Apply the styles for the Mobile Controls

<mobile:stylesheet id="mobileStyleSheet" runat="server">

       <mobile:style size="Small" name="Arial"></mobile:style>

   </mobile:stylesheet>

//Bind the SharePoint ListItem

<mobile:objectlist stylereference="ObjectList" id="olMobile" onprerender="olMobile_PreRender" runat="server">

          <devicespecific id="ds" runat="server">

               <choice>

                   <headertemplate>

                             Title

                   </headertemplate>

                   <itemtemplate>

                             <a href="javascript:void(0);"><%#Eval("Title") %></a>

                             <p><mobile:label id="lbDescription" runat="server"></mobile:label>

                             <mobile:link id="lnkUrl" runat="server">read more...</mobile:link></p>

                   </itemtemplate>

                   <footertemplate>

                          

                   </footertemplate>

               </choice>

          </devicespecific>

     </mobile:objectlist>

C# Code:

protected void Page_Load(object sender, EventArgs e)
{
using (SPSite spSite =new SPSite("http://servername:portnumber"))
{
SPWeb spWeb = spSite.OpenWeb();
spWeb.AllowUnsafeUpdates = true;
SPList spList = spWeb.Lists["ListName"];
SPQuery spQuery = new SPQuery();
spQuery.Query = "";
SPListItemCollection listitems= spList.GetItems(spQuery);
olMobile.DataSource = listitems.GetDataTable();
olMobile.DataBind();
spWeb.Dispose();
spWeb.AllowUnsafeUpdates = false;

}

}

protected void olMobile_PreRender(object sender, EventArgs e)
{
foreach (ObjectListItem item in olMobile.Items)
{
System.Web.UI.MobileControls.Link lnkUrl = (System.Web.UI.MobileControls.Link)item.FindControl("lnkUrl");
System.Web.UI.MobileControls.Label lbDescription = (System.Web.UI.MobileControls.Label)item.FindControl("lbDescription");

DataRowView drv = (DataRowView)item.DataItem;

lnkUrl.NavigateUrl = drv["Url"].ToString();
lbDescription.Text = drv["Description"].ToString();
}
}

Friday, July 3, 2009

Site Content type Gallery is Empty

After Creation of Site Collection we need to restart the iis (iisreset /noforce).
Unless and until if you didn't restart the iis you cant see the site content types in the site content type gallery.
So, make sure that the iis is resert as soon as site collection is created.