Thursday, December 8, 2011

A Project Item with the following item ID could not be found

In SharePoint 2010, this error may occur.

it happens when you delete/exclude any item in sharepoint project.

The solution is :-  goto the feature(mentioned in the error in visual studio)  try to find the problematic file.

The file will be identified easily. just remove that file from the "Items in the future"  section.

the problem will be solved. (it worked for me)


happy coding.....:-)










Word experienced an error trying to open the file

Thanks to author @ http://blog.techgalaxy.net/archives/3042

the problem is occurred while opening doc file (created in 2007) in office 2010.

the trick to open the file is


  1. Open Word 2010.
  2. Click File, Options, Trust Center, Trust Center Settings.
  3. Select the Protect View option.
  4. Deselect all the Protected View options. You may not have to disable Data Execution Prevention mode. Experiment with the various options until you get the results.

Tuesday, December 6, 2011

Monday, November 21, 2011

SharePoint Get list item parent folder

thanks to author @ http://blogs.tamtam.nl/appie/2009/02/23/Getting+ParentFolder+From+A+Custom+List.aspx

we can use the following method to get parent folder of listitem


static SPFolder GetParentFolder(SPListItem itemToFind, SPFolder folder)
{
      SPQuery query = new SPQuery();
      query.Folder = folder;
      SPListItemCollection items = itemToFind.ParentList.GetItems(query);
     
      foreach (SPListItem item in items)
      {
            if (item.ID == itemToFind.ID)
            {
                  return (folder);
            }
            if (item.Folder != null)
            {
                  SPFolder resultFolder = GetParentFolder(itemToFind, item.Folder);
                  if (resultFolder != null)
                  {
                        return (resultFolder);
                  }
            }
      }

      return (null);
}


So adding that function allows you to get a parentfolder with:

SPFolder parentFolder = GetParentFolder(item, null);







Thursday, November 17, 2011

Get only folders from SharePoint list

thanks to author @ http://www.ktskumar.com/blog/2009/07/retrieve-all-folders-from-list/


the trick is FSObjtype=1.
Use this while querying the list

query.Query = “<Where><Eq><FieldRef Name=’FSObjType’/><Value Type=’Lookup’>1</Value></Eq></Where>”


Monday, November 14, 2011

SharePoint 2010 Empty Recycle Bin


Thanks to author @

http://dhireny.blogspot.com/2010/06/empty-all-items-from-sharepoint-recycle.html#!/2010/06/empty-all-items-from-sharepoint-recycle.html

the trick is
goto recylebin page, then paste this in addressbar textbox in browser

javascript:emptyItems();


then press enter, thats it









SharePoint 2010 + webpart page with quick launch

thanks to author @ http://pscave.blogspot.com/2010/10/show-quick-launch-on-sharepoint-2010.html

the steps are

Delete the following from your webpart page

1.
         < asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server"></asp:Content>

2.
< asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server"></asp:Content>

3.
< style type="text/css">
body #s4-leftpanel {
display:none;
}
.s4-ca {
margin-left:0px;
}
</style>




Friday, October 14, 2011

CAML query on number field with BeginsWith--Work around

I faced problem when I tried to filter my list with BeginsWith operator on number column. It may treat the condition as "Eq" because of the Data type Number.

The work around I found is , create another column as Calculated. The twist here is , again it considers the condition as "Eq". So the formula i used is "=CONCATENATE("A",Column1)". Select the data type of Calculated field as Single Line Of Text.

Now my condition to filter is  <BeginsWith> <Value>A + our Field Value</value>

My Code is here:-

Create Calculate Field
strDispName = lstFAS.Fields.Add(strDeptColName + "Dup", SPFieldType.Calculated, false);
                fldCalc = (SPFieldCalculated)lstFAS.Fields[strDeptColName + "Dup"];
                fldCalc.Formula = @"=CONCATENATE(""A"",[Department])";
                fldCalc.Update();


Query
SPQuery queryFAS_ByCondition = new SPQuery();
                        queryFAS_ByCondition.Query = string.Format("<Where><BeginsWith><FieldRef Name='DepartmentDup' /><Value Type='Text'>{0}</Value></BeginsWith></Where>",
                                                               "A"+lstItemFASSiteFinder_ByID.Title);


The code may look ugly, but hey it worked for me.

happy coding....:-)

Thursday, September 15, 2011

SharePoint Foundation + edit/update excel files programatically in Document library

Voila.....finally its working.....:-)

After googling for hours together finally found the appropriate codes/links

my requirement is quite simple (???)

update/edit the excel files in my document library programatically. Sounds simple.....huh?

The real problems occur when we start working towards the requirement.

problem 1.   Server will not have excel dlls to work with.
problem 2.  Jet/ACE drivers giving lot of error while using  (using OLEDB)
Problem 3. Cannot trust third party dlls

Finally microsoft/other sites shed some light on how to use Open XML for this scenario.

http://howtosharepoint.blogspot.com/2010/05/programmatically-edit-and-save-file.html

http://msdn.microsoft.com/en-us/library/ee956524.aspx


I've created one class with the methods given in Open XML.

Created one method as below

public static MemoryStream UpdateMe2(MemoryStream memStr, string sheetName, string strCellName, string strVal)
       {

           using (SpreadsheetDocument document = SpreadsheetDocument.Open(memStr, true))
           {
               WorkbookPart wbPart = document.WorkbookPart;

               UpdateValue(wbPart, sheetName, strCellName, strVal, 0, true);
               return memStr;
           }

           return null;
       }




Tuesday, September 13, 2011

SharePoint Timer jobs Access denied on feature activation

Thanks to Kshitijb  @
http://social.msdn.microsoft.com/Forums/en-US/sharepoint2010general/thread/f41810ec-2348-436d-a574-c29656f3a567/

Refer this link for detailed explanation.
http://stackoverflow.com/questions/1036589/problem-in-creating-timer-job


The problem is , my feature has scope site.

Timerjob's feature Scope should be web application or Farm.

It solved my problem.

BUT I do remember, I have some timer jobs with scope web and are running fine. (This is NOT recommended)


SharePoint Webpart Page with quick launch

With SharePoint 2007 all you needed to do was edit the page in SharePoint Designer and remove the following 2 lines:

< asp:Content ContentPlaceHolderId="PlaceHolderNavSpacer" runat="server">
< asp:Content ContentPlaceHolderId="PlaceHolderLeftNavBar" runat="server">

With SharePoint 2010 you also need to delete the following:

< style type="text/css">
body #s4-leftpanel {
display:none;
}
.s4-ca {
margin-left:0px;
}



Thanks To the author @

http://pscave.blogspot.com/2010/10/show-quick-launch-on-sharepoint-2010.html

Monday, August 22, 2011

Failed to instantiate file from module The specified list does not exist.

Hi
In case anyone else has this problem try to change

Type="GhostableInLibrary" to

Type="Ghostable"

worked for me


Here I am trying to deploy master page my elements.xml file is like below after modification










Thanks to the author @

http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/27ac36ca-3d3a-47eb-9fc6-ee1b1846b8a3/


http://vspug.com/george/2008/02/05/failed-to-instantiate-file-quot-file-ext-quot-from-module-quot-modules-quot-the-specified-list-does-not-exist/

sharepoint 2010 Datetime field default value + add days

You can set datetime default field value not only Today, but you can have your own calculated value.

select any datetime field--->for default value select "Calcualted Value"

then you can give =TODAY()+ 10


for one year---->its =TODAY()+365

Thursday, August 18, 2011

sharepoint 2010 + item event receivers + session

I've been googling for last couple of hours for the correct post.

"How to use sessions in sharepoint item event handlers"

finally I could find the correct link(see below). Thanks to the author.

In a nut shull, it is available in synchronous events (adding, updating).
Not available in Async events (Added, Updated).

define a variable in receiver class, assign the HttpContext.Current in default constructor.


HttpContext hContext = null;

public MyCustomEventHandler() : base()
{
hContext = HttpContext.Current;
}


public override void ItemAdding(SPItemEventProperties properties)
{
hContext.Response.Redirect(“http://microsoft.com”)
}



http://blogs.msdn.com/b/sowmyancs/archive/2008/03/25/can-we-get-the-httpcontext-in-custom-event-handlers-in-sharepoint.aspx

Friday, March 18, 2011

sharepoint list data to excel, programatically

thanks to the author,

http://avinashkt.blogspot.com/2009/05/programmatically-export-records-from.html

here is the trick

string spListName = "CartDetails";
SPList oList = SPContext.Current.Web.Lists[spListName];
string listGUID = oList.ID.ToString().ToUpper().Replace("-", "\u00252D");
string viewGUID = oList.DefaultView.ID.ToString().ToUpper().Replace("-", "\u00252D");
strCommand = "javascript:EnsureSSImporter();" +
"javaScript:ExportList('\u002f_vti_bin\u002fowssvr.dll?CS=65001\u0026"
+ "Using=_layouts\u002fquery.iqy\u0026" + "List=\u00257B"
+ listGUID + "\u00257D\u0026" + "View=\u00257B" + viewGUID
+ "\u00257D\u0026" + "RootFolder=\u00252FLists\u00252F"
+ spListName.Replace("_", "\u00255F") + "\u0026" + "CacheControl=1')";

btnExportToExcel.Attributes.Add("onclick", strCommand+"; return false;");

Thursday, March 10, 2011

SharePoint SPMetal + CreatedBy, Created

string _CreatedBy;
[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "Author", Storage = "_CreatedBy", ReadOnly = true, FieldType = "User", IsLookupValue = true)]
public string CreatedBy { get { return this._CreatedBy; } set { if ((value != this._CreatedBy)) { this.OnPropertyChanging("CreatedBy", this._CreatedBy); this._CreatedBy = value; this.OnPropertyChanged("CreatedBy"); } } }


DateTime _Created;
[Microsoft.SharePoint.Linq.ColumnAttribute(Name = "Created", Storage = "_Created", ReadOnly = true, FieldType = "DateTime", IsLookupValue = false)]
public DateTime Created { get { return this._Created; } set { if ((value != this._Created)) { this.OnPropertyChanging("Created", this._Created); this._Created = value; this.OnPropertyChanged("Created"); } } }


1 Name="Editor" Member="ModifiedBy"
2 Name="Author" Member="CreatedBy"
3 Name="Created"
4 Name="Modified"

Monday, March 7, 2011

javascript convert number to currency . ex:- 1234.56, 1234.00

Thanks to the author, I missed the original link

function CurrencyFormatted(amount) {
var i = parseFloat(amount);
if (isNaN(i)) { i = 0.00; }
var minus = '';
if (i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if (s.indexOf('.') < 0) { s += '.00'; }
if (s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}

asp.net gridview, column total in footer using java script

Thanks to the author @ http://forums.asp.net/t/1168003.aspx
--------------------
In my grid I have one label in template field which stores item price, I want to show the total of items on label in footer.

function RetrievePackageDetailInputs() {
try {
var totVal = 0;
rows = document.getElementById('<%= gvCartDetails.ClientID %>').getElementsByTagName("TR");
for (var j = 1; j < rows.length - 1; j++) { cells = rows[j].getElementsByTagName("span"); if (cells.length > 0) {
totVal = Number(totVal) + Number(cells[0].innerHTML);
}
}
rows[rows.length - 1].getElementsByTagName("span")[0].innerHTML =CurrencyFormatted(totVal);
}
catch (er) {
// Non-critical error
alert(er.description);
}
}

Monday, February 28, 2011

How do you put multiple batch file commands in a single line?

dir & dir

should be working.

where "DIR" is one command

Active Directory users are not shown in People Picker of the permissions + SharePoint

problem might be , the application pool's identity is unable to access AD users. So change the application pool's identity to domain user (basically service A/c).

goto Security--> Configure Service Accounts-->select the application pool of the specific web application, then select the service a/c.

(Im using SF 2010)

It worked for me. It saved my day.

Tuesday, February 22, 2011

sharepoint foundation + delete item + Cannot complete this action.

I have created some lists & related lists using object model. Im changing my column names also at the time of creating the field with SPRelationshipDeleteBehavior.

when I try to delete the item in parent list, istead of showing the message "This item cannot be deleted because ....." , it threw error like "Cannot complete this action...", when I check log , no luck. (found one related to lock, not sure what it is).

Then after long trial and error methods, I changed my code to two parts.
1. Create lists and related lists
2. for the specific fields set deleterelationshipBehaviour

from then its working. I guess the field name might cause the error, as index is created using old name.

add additional fields in sharepoint list 2010, using object model

http://msdn.microsoft.com/en-us/library/ff623048.aspx

here is the logic

string strFirstNameCol = relatedList.Fields.AddDependentLookup("First Name", primaryCol.Id);
SPFieldLookup firstNameCol = (SPFieldLookup)relatedList.Fields.GetFieldByInternalName(strFirstNameCol);


where, "primaryCol" is the main look up field in the second list.

Thursday, February 17, 2011

The language-neutral solution package was not found

Sometimes u get this error while deploying ur package, then u can try the following commands in sharepoint 2010 powershell

//find the deployed solutinos
get-spsolution

//then replace mysol with ur solution
(get-spsolution mysol.wsp).Delete()

then try to deploy ur sol. again

--happy coding

SharePoint Custom fields

1. Thanks to jeremyluerken for writing such a wonderful article (custom picker in SP 2010)

http://sharepointsolutions.com/sharepoint-help/blog/2009/10/create-a-custom-picker-in-sharepoint-2010/


2. Thanks to Waldek Mastykarz for his marvelous work, i've been lookin for this kind of solution for a long time, finally found this.
(Custom picker, fill multiple fileds at a time)

http://blog.mastykarz.nl/filling-forms-entitypicker-callback/

Thursday, January 27, 2011

Timer jobs in sharepoint (WSS) subsites

http://sharepoint2010shyju.blogspot.com/2010/12/creating-custom-timer-job.html?showComment=1296184785817#c3173481420652015259

please refer this link. I must say thanks to the author Mohan for his great post.

the logic is

1. use the properties like below in ur timer job class

[Persisted()]
public string MyCustomProperty;

2. assign the url of the web (site/subsite..whatever) to the property in feature activated event

SPWeb webN = properties.Feature.Parent as SPWeb;
taskLoggerJob.MyCustomProperty = webN.ServerRelativeUrl;

Note:- my scope is web

3. Use the property in Execute method

SPSite _siteCol = new SPSite(this.WebApplication.Sites[0].Url);
SPWeb _site = _siteCol.AllWebs[MyCustomProperty]; //

Note:- I have one site collection, (u can refer ur site collection using contentdbId)

:-), thats it...Happy coding

Thursday, January 13, 2011

SharePoint Foundation + Search Server 2010

http://sptechpoint.wordpress.com/2010/11/30/your-search-cannot-be-completed-because-this-site-is-not-assigned-to-an-indexer/

This blog saved my day. Once you install the SSE, u have to configure it in Central Admin site

1. Go to Central Admin as login as the farm Administrator

2. Go to Application Management tab

3. Select SharePoint Web Application Management heading | Content databases

4. Ensure your web application is the one selected

5. Select your content database name

6. Under Search Server – select your server (if your search server drop down is disabled please follow the additional steps below)

7. Go to 12 hive folder and open stsadm.exe utility

8. Run the following command psconfig.exe -cmd services -install

9. Then run stsadm -o spsearch -action start (specify the farm account if required)


Thnx to the author of the mentioned link