20 December 2011

Export SharePoint 2010 sites list to Excel File

How to get the SharePoint 2010 sites list to Excel using Powershell?

Go to SharePoint 2010 Management Shell.


You have to open the Web Application, then the Site Collection, after Select the Fields and Export to Excel (csv file)
$Get-SPSite | Get-SPWeb | Select url,title | Export-Csv



All this on one line in PowerShell, just think how much time it saves time instead of building a console application.

Yours
Roi

18 December 2011

Sharepoint 2007 Crawl Never Ends - Always Status Crawling

I had "Not Stopped the Search Index Crawler " case in SharePoint 2007 (in “Crawling” status indefinitely) and doesn't respond to stop requests
I had not stopped the search case "Stop Crawl"
But nothing - stuck "Stopping"

The solution:
 Enter the following stsadm commands : execadmsvcjobs, osearch -action stop, -o osearch -action start -role Index

C:\>stsadm -o  execadmsvcjobs
Executing .
Operation completed successfully.
C:\ >stsadm -o osearch -action stop
The Office SharePoint Server Search service was successfully stopped.
C:\>stsadm -o osearch -action start -role Index
The Office SharePoint Server Search service was successfully started.

Now you need to do - Reset all craweld content



Now re-run the indexing, this should solve the problem.

Hope I helped,
Roi

15 December 2011

SPListItem​Collection to Linq List

This time you code gives us extension to SPListItemCollection object.

SPListItem​Collection to Linq List

If you want to work with the object of SPListItemCollection using linq - The following code can help

public static List<SPListItem> ToList(this SPListItemCollection items)
{
    IEnumerable<SPListItem> itemsContiens = items.OfType<SPListItem>();
    return itemsContiens.ToList<SPListItem>();
}

Yours...
Roi

14 December 2011

The underlying connection was closed: An unexpected error occurred on a receive

When I tried to access an external server on the server side (not the organization) through the code (in my case web-part of sharepoint) I got an error:

The code is simple code:

public XmlDocument GetXmlData()
{
    XmlDocument document = new XmlDocument();
    //Now load the XML Document
    document.Load(this.url);// fall
    return document;
}

The error I got it:

   The underlying connection was closed: An unexpected error occurred on a receive.

   Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

   at System.Net.HttpWebRequest.GetResponse()
   at System.Xml.XmlDownloadManager.GetNonFileStream(Uri uri, ICredentials credentials)
   at System.Xml.XmlDownloadManager.GetStream(Uri uri, ICredentials credentials)
   at System.Xml.XmlUrlResolver.GetEntity(Uri absoluteUri, String role, Type ofObjectToReturn)
   at System.Xml.XmlTextReaderImpl.OpenUrlDelegate(Object xmlResolver)
   at System.Threading.CompressedStack.runTryCode(Object userData)
   at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
   at System.Threading.CompressedStack.Run(CompressedStack compressedStack, ContextCallback callback, Object state)
   at System.Xml.XmlTextReaderImpl.OpenUrl()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(String filename)
   ...

In Visual Studio it looks like this:
The underlying connection was closed: An unexpected error occurred on a receive

I tried to execute the code in another request.
Then in another Thread.
And almost before I gave up, I tried to do impersonation with another user.
Nothing works....

Then I realized the problem - is the problem of information security.
I defined proxy in web.config - and cheers .... It works

Setting in web.config

  <system.net>
    <!--proxyaddress is the url address of the Company with the port-->

     <defaultProxy>
       <proxy usesystemdefault="True" proxyaddress="http://myporxy:port" bypassonlocal="True" />
     </defaultProxy>
   </system.net>

Hope I helped,
Roi

11 December 2011

Update SharePoint fields on Client-Side with spservices

This time I will present a client-side code (JavaScript) - which updates a list of fields without having to insert the data (edit) into the form.

All you need is another class from beloved and familiar - jquery that Called- spservicehttp://spservices.codeplex.com/
It works in 2007 and 2010 because the code in the form ajax turns  to the sharepoint web-service. (Although in 2010 we have the "Client Object Model").
The following code built two objects - an image and textbox


I make an update of the field after clicking on the image, and then I prevent users from updating again.
Please note, I use the method of spservice SPUpdateMultipleListItems.
The method get the following variables:
webURL, listName, CAMLQuery, batchCmd, valuepairs, debug

...
  <input type="text" id="txt<%=this.UniqueID%>" class="myClass1" value="<%=likeValue%>" />
  <img class="myClass2" id="btn<%=this.UniqueID%>" src="/_layouts/images/img.gif" alt="" />
...  
<script type="text/javascript">
    $(document).ready(function () {
        // The id$= is doing a regex match for an id ENDING with btn.
        var btn = $("img[id$='btn<%=this.UniqueID%>']");
        btnLike.click(function () {
            var txt = $("input[id$='txt<%=this.UniqueID%>']");
            var myValue = parseInt(txt.val()) + 1;
            var strVal = myValue.toString();
            $().SPServices.SPUpdateMultipleListItems(
                {
                    webURL: "<%=webUrl%>",
                    listName: "<%=listName%>",
                    CAMLQuery: "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Counter'><%=itemId%></Value></Eq></Where></Query>",
                    batchCmd: "Update",
                    valuepairs: [["<%=field1%>""..."], ["<%=field2%>", strVal]],
                    debug: true
                });
            txt.val(myValue);
            txt.attr("disabled""disabled");
            btn.attr("disabled""disabled");
        });
    });
</script>

Now you can update an item on every page with the content editor web-part that add the JS code.
I do not think the syntax is complicated,
If you have any questions, I'm here

Yours,
Roi Kolbinger