This is a nasty SharePoint bug which caused some trouble in one of the SharePoint Online environments I was working on.

I created a Site Template using the “Save site as template” feature of SharePoint. Now when I created a new site from the template it resulted in the web parts all mixed up in the Left web part zone. Remarkably it was only the Left zone, the others were keeping their correct web part sequence.

When I took a look in the Onet.xml of the Site Template the web parts were nicely divided into seperate AllUsersWebPart’s and having correct WebPartZoneId’s. And although the web parts were also mixed up in the XML, the WebPartOrder properties were set correctly, 1 for the first, 2 for the second and so on. I still tried to rearrange the XML so the web parts would also have the right sequence in the syntax, but with no success, the web parts were still mixed up.

The final thing to do was to create a Web Part Zone for each Web Part. I did this by opening the page in SharePoint Designer and edit in the Advanced Mode (button on the ribbon).

This way the order is hardcoded on the page. I admit, it’s not very neat, but it does the trick.

I looked for hours! I can’t find this thing anywhere else on the internet! There must be a complete group of developers and designers that have been struggling with this before! I can’t believe I’m supposed to be the first one to put this solution on the world wide web.

All I wanted to do is to disable the wordwrap in a specific div in SharePoint, like so:

white-space: nowrap;

It worked perfectly in all browsers, except for… That’s right! Internet Explorer!

After struggling for half a day I finally found out that SharePoint inserts another piece of styling called word-wrap. This is the SharePoint code:

word-wrap: break-word;

All I had to do is override this in my own style and voila, it finally works!

And now the working style looks like this:

white-space: nowrap;word-wrap: normal;

I was so lucky = to receive this error. It may be a bug in Sharepoint (Designer) or I may be the only one that has this problem. I hope you don’t have this “bug”, for them who have the same problem, here is the solution:

I was working on another custom page of EditForm.aspx, I have a DataForm Webpart on  the page showing me the data the way I want it. On that Dataview I have a few text fields and also a Yes/No field. I wanted the user to only see this yes/no field and not edit it.

So I go to the page with Sharepoint designer and select the field and in the properties setting the attribute ControlMode from “Edit” to “Display”. This worked fine in SPD but when I did go to the EditForm in Sharepoint I was getting the following error “An unexpected error has occurred”.  There was not much else I could change or try to resolve this. There isn’t just a property or value that needs to be set to get this working.

The ONLY way to make the page display the way you want in Sharepoint is the next one:

Go to the page in sharepoint designer, the current state of the field isn’t important. Click on the Yes/No field in the design view. Click on the arrow next to the selected field and change format to Boolean. You now see a Yes or No on the page. When you are in split view you can see a <xsl: when … /xsl:otherwise>. In this code you can change the black Yes and No between the tags to a yes and no in your preferred language. In my case that would make Yes -> Ja and No -> Nee.

The code will look like this:

<xsl:choose>
<xsl:when test=”@Klant_x0020_geinformeerd=’1′ or msxsl:string-compare(string(@Klant_x0020_geinformeerd),’Yes’,”,’i’)=0 or msxsl:string-compare(string(@Klant_x0020_geinformeerd),’True’,”,’i’)=0″>Ja</xsl:when>
<xsl:otherwise>Nee</xsl:otherwise>
</xsl:choose>
<xsl:choose>

    <xsl:when test="@YesNoField='1' or msxsl:string-compare(string(@YesNoField),'Yes','','i')=0 or msxsl:string-compare(string(@YesNoField),'True','','i')=0">Ja</xsl:when>

    <xsl:otherwise>Nee</xsl:otherwise>

</xsl:choose>

Save, go to Sharepoint and enjoy your working form.

A few days ago I started making a custom NewForm.aspx for a list with Sharepoint Designer. I started hiding the default list form webpart and inserted a custom list form. I tweaked this the way I wanted and it worked like charm. But, with testing I found out that I couldn’t upload any attachments. When I clicked the “Attach File” button nothing happens.

I debugged the javascript that was behind the “Attach File” button. There I found the following piece of code:

function ShowPartAttachment()
{
 if (document.getElementById("part1")==null ||
 typeof(document.getElementById("part1"))=="undefined")
 {
 var L_FormMissingPart1_Text= "This form was customized not working with attachement.";
 alert(L_FormMissingPart1_Text);
 return;
 }
 document.getElementById("part1").style.display="none";
 document.getElementById("partAttachment").style.display="block";
 GetAttachElement(FileuploadString+FileUploadIndex).focus();
}

You can see that it tries to hide part1 and shows partAttachment. In my source I found both spans, but the part1 span was holding the hidden listview webpart that was off course already hidden. This is just another bug in Sharepoint Designer.

I started searching the internet for a fix to this problem and came along a post that refers to the following hotfix for sharepoint designer http://support.microsoft.com/kb/960311 and WSS update http://support.microsoft.com/kb/951695. After applying these fixes, I recreated the custom listview. You can also manually edit an existing custom listview by applying a few lines of code that is given here http://support.microsoft.com/default.aspx?scid=kb;en-us;953271&sd=rss&spid=11373, but I recommend deleting and recreating the listview.

This however didn’t solve anything. When I looked a bit closer at the code I saw that the “part1” span was in place and it theoratically should work. After spending some hours to solve this problem I tried to delete the hidden listview, cause I thought it might interfere, and it did! It’s quite obvious because two spans with the id “part1” are on the page and it hides the first one.

We are working with Sharepoint and one typical Sharepoint issue is that when one problem is solved the next pops up. And indeed this is the case. The form worked fine when I did go to AllItems.aspx, but it now throws an error when clicking “New” in the list overview saying “Invalid page URL” and some users getting “An unexpected error has occurred”. The solution is fairly simple: just don’t delete the List Form Web Part, but I did already =|. So I copied the List Form Web Part from a backup back to the site. If you ran into the same situation but don’t have a backup, don’t bother inserting a new List Form Web Part but just copy it from your EditForm.aspx and doing some small modifications. Here are the instructions for doing this: http://blogs.msdn.com/dszabo/archive/2007/02/20/custom-list-newform-aspx-ruined-in-wss-3-0.aspx

Now when I was back where I started I just moved the custom Listview to the top by dragging and dropping in Sharepoint Designer making it the first webpart on the screen. This did solve allmost everything, I could open the new form normally and upload attachments to it.

However as I said before, when one problem is solved the next pops up. Now, when I fill the form and save it I get a brand new error:

“Failed to get value of the “Attachments” column from the “Attachments” field type control. See details in log. Exception message: Guid should contain 32 digits with 4 dashes (xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)”

The attachments of the two webparts are conflicting so I made the compiler convince that the hidden List Form isn’t a ListForm by edit the following line in the NewForm.aspx in sharepoint designer:

<TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">ListForm</TemplateName>

to

<TemplateName xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">NoListForm</TemplateName>

this way the hidden List Form is still there but doesn’t conflict. The form works perfectly fine for me now.

update:

I found out that for the first new item in the list I cannot attach any files, because there is no “attach file” button. For any other new item it worked, but simply not the first one =S

However, there is a solution to this also. Just change the following in the NewForm.aspx and everything will work fine:

<ControlMode xmlns="http://schemas.microsoft.com/WebPart/v2/ListForm">Edit</ControlMode>

to

<ControlMode xmlns=”http://schemas.microsoft.com/WebPart/v2/ListForm”>Display</ControlMode>

Another update:

Some readers had a problem which is described as “When I try to add attachments to an existing list entry (Edit form) the file attachment dialog doesn’t close when hitting OK.”or “When i click the button to “Attach File”, I now get to the page where I can attach a file, however, after selecting a file when I click “Ok”, nothing happens and I get an “Error On Page” ”

Now one of my readers came with a solution to this problem. When you click on the “OK” button of the attach dialouge after selecting a file, a javascript action occurs, where it takes your selected file and adds it to a table with ID= “idAttachmentsRow”. Now, if this table does not exist, then you will get a javascript error on the page. The reason this table doesnt exist for you is because you have modified your custom new/edit form in the past and deleted your attachments form field. Without the attachments form field you cannot complete the attachment use case. I think the following code will help you (it is tailored for edit forms, but a few small changes it will work for new forms as well)

var elm = document.getElementById(“idAttachmentsTable”);
if (elm == null || elm.rows.length == 0)
document.getElementById(“idAttachmentsRow”).style.display=’none’;

or

Just make a new page. in the new page, add a custom list form. Look at the code generated for the custom list form. At the bottom, it will have your attachments field that you are probably missing. Copy and paste that attachments field into your problem form and you should be good to go.

Credits go to pete w for these solutions.

I thought there was a simple method like MoveTo or CopyTo to move one listitem to another sharepoint list. MoveTo doesn’t exist and CopyTo didn’t behave like expected.

So I started looking on the internet and what I found was that the SPImport and SPExport classes did the job. There is a 6-part writeup at http://blogs.technet.com/stefan_gossner/archive/2007/08/29/deep-dive-into-the-sharepoint-content-deployment-and-migration-api-part-2.aspx. This however is an overkill for what I tried to accomplish.

Finally I made a function that copies all the fields and attachments one by one to another listitem.

Here is the code:

private void moveListItem(String destinationListName)

        {

            //creating new listitem at the destination list

            SPWeb web = workflowProperties.Web;

            SPList destList = web.Lists[destinationListName];

            SPListItem destListItem = destList.Items.Add();

            SPListItem sourceListItem = workflowProperties.Item;

            //transfer fields from sourceListItem to destListItem

            foreach (SPField field in sourceListItem.Fields)

            {

                if (!field.ReadOnlyField && !field.Hidden && field.InternalName != "Attachments")

                {

                    if (destListItem.Fields.ContainsField(field.InternalName))

                    {

                        destListItem[field.InternalName] = sourceListItem[field.InternalName];

                    }

                }

            }

            //move all attachments one by one to the new listitem

            SPAttachmentCollection attColl = sourceListItem.Attachments;

            foreach (string fileName in attColl)

            {

                SPFile attFile = sourceListItem.ParentList.ParentWeb.GetFile(sourceListItem.Attachments.UrlPrefix + fileName);

                StreamReader fsReader = new StreamReader(attFile.OpenBinaryStream());

                Stream fStream = fsReader.BaseStream;

                byte[] contents = new byte[fStream.Length];

                fStream.Read(contents, 0, (int)fStream.Length);

                fStream.Close();

                fStream.Dispose();

                destListItem.Attachments.Add(fileName, contents);

            }

            destListItem.Update();

            sourceListItem.Delete();

        }
private void moveListItem(String destinationListName)
{
//creating new listitem at the destination list
SPWeb web = workflowProperties.Web;
SPList destList = web.Lists[destinationListName];
SPListItem destListItem = destList.Items.Add();
SPListItem sourceListItem = workflowProperties.Item;
//transfer fields from sourceListItem to destListItem
foreach (SPField field in sourceListItem.Fields)
{
if (!field.ReadOnlyField && !field.Hidden && field.InternalName != “Attachments”)
{
if (destListItem.Fields.ContainsField(field.InternalName))
{
destListItem[field.InternalName] = sourceListItem[field.InternalName];
}
}
}
//move all attachments one by one to the new listitem
SPAttachmentCollection attColl = sourceListItem.Attachments;
foreach (string fileName in attColl)
{
SPFile attFile = sourceListItem.ParentList.ParentWeb.GetFile(sourceListItem.Attachments.UrlPrefix + fileName);
StreamReader fsReader = new StreamReader(attFile.OpenBinaryStream());
Stream fStream = fsReader.BaseStream;
byte[] contents = new byte[fStream.Length];
fStream.Read(contents, 0, (int)fStream.Length);
fStream.Close();
fStream.Dispose();
destListItem.Attachments.Add(fileName, contents);
}
destListItem.Update();
sourceListItem.Delete();
}