28 January 2012

Cannot assign to 'obj' because it is a 'foreach iteration variable'

I asked during a job interview is there a difference between for to foreach are not in terms of performance in terms of working with objects. Can I update the same set of both?
Desalination to see which candidate did not know the answer.
I'm not going to explain who was stronger for or foreach.
That you can read the article by Dustin Campbell - Performance of foreach vs. List.ForEach.
So I'll give a practical example, explain the difference from for to foreach when both cases I'm going to update my system.

Here's the code for example:
Is for or/and  foreach will update the List?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace CheckFor
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> arr = new List<string>();
            arr.Add("aaa");
            arr.Add("bbb");
            arr.Add("ccc");
            arr.Add("ddd");
            arr.Add("eee");
            arr.Add("fff");
            for (int i = 0; i < arr.Count; i++)
            {
                arr[i] = arr[i].ToString() + arr[i].ToString();
            }
            foreach (string obj in arr)
            {
                obj = obj + obj;
            }
        }
    }
} 

Then there are those straight to see a foreach loop can not update items because it actually makes a copy for collection, while a for loop can update the objects because it really is on the objects.

Again, I'm not going to explain what it means by value and by reference.
But if you meet the following message - remember the meaning of objects update

Cannot assign to 'Your object' because it is a 'foreach iteration variable'

Example of the error

Cannot assign to 'obj' because it is a 'foreach iteration variable'

Yours,
Roi

16 January 2012

SharePoint - Export to Spreadsheet (excel) Not Work

Did you have a case where you wanted to work in Excel at sharepoint list view, but you had no some fields (like lookup field)?
Can not "Export to Spreadsheet"?

I had the case!
Two solutions:
1 - Install SPD (is free).
2 - Because not every time we run straight to install the SharePoint Designer.
The solution to install SharePoint.ExportDatabase activeX.

Here's how to install the activeX of the excel
Run from Address Bar this code

javascript: var x =new ActiveXObject("SharePoint.ExportDatabase");


Address bar
To see that it worked, do the following ...

1. Go to (from IE) tools -> Internet Option

Internet Option
2. Programs -> Manage add-ons

Manage add-ons
3. All add-ons

All add-ons
And see that ActiveX is enable :)

There are more activexs needed to operate the sharepoint
javascript: var x = new ActiveXObject("Microsoft.XMLDOM");
javascript: var x = new ActiveXObject("ListNet.ListNet");
javascript: var x = new ActiveXObject("DiagramLaunch.DiagramLauncher");

If it does not help - you have to install SPD :(
Yours.
Roi

08 January 2012

Webpage error details. Object required


Not long ago, I created a new master-page (from scratch) at SharePoint Designer.
I'm done to add all the controls - looks good!
But when I started working with web-parts - had a little problem. Drag and Drop did not work.

I received the following error:

Webpage error details
User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; .NET4.0C; .NET4.0E)
Timestamp: Sun, 8 Jan 2012 11:46:30 UTC

Message: Object required
Line: 1571
Char: 3
Code: 0
URI: http://yoururl/ie55up.js



Webpage error details. Object required


Google search brought me to the following blog:
Neil Mosafi  - http://neilmosafi.blogspot.com/2007/11/sharepoint-dragging-webparts-causes.html
When I added the code - he really helped me

<script language="javascript" type="text/javascript">
function MSOLayout_GetRealOffset(StartingObject, OffsetType, EndParent)
{
  var realValue=0;
  
if (!EndParent) 
    EndParent=document.body;
  
for (var currentObject=StartingObject; currentObject && currentObject !=EndParent && currentObject != document.body; currentObject=currentObject.offsetParent)
  
{
    
var offset = eval('currentObject.offset'+OffsetType);
   
if (offset)

      realValue+=offset;
  
}
  
return realValue;
}

</
script>

thanks Neil :)

Something I want to emphasize - it put the code as much as possible at the end of the page.

Hope I helped,
Roi