Issues Uploading Office 2003 docs to SP 2010 Programmatically

2013-05-14 Thread Nigel Witherdin
Hi All,
We are using an in-house developed tool to upload files from old DMS into 
SharePoint 2010, and are finding we are having issues with Office 2003 docs. 
The tool uploads the file, sets content type, and then set metadata (as read 
from a CSV). This all works fine for PDFs, DOCXs, etc. but it does not work 
with DOCs. Frustratingly, it doesn't report any errors, and the logging info 
looks just fine for these files.
Instead of being set to the specified content type, they are always set to the 
default content type of the library, and do not have the metadata values set as 
expected.
The code being used to upload the file and set the content type (both ways it 
has been tried) is:
targetList.ParentWeb.ParserEnabled = false;
targetList.ParentWeb.Update();
//Hashtable ht = new Hashtable();
//ht.Add(ContentTypeId, targetCt.Id.ToString());
//ht.Add(ContentType, targetCt.Name);
//SPFile file = targetFolder.Files.Add(filename, fs, ht, true); 
   //file.Update();
SPFile file = targetFolder.Files.Add(filename, fs, true);   
 file.Update();file.ParentFolder.Update();
file.Item[SPBuiltInFieldId.ContentTypeId] = targetCt.Id;
file.Item[SPBuiltInFieldId.ContentType] = targetCt.Name;
file.Item.UpdateOverwriteVersion();
targetList.ParentWeb.ParserEnabled = true;
targetList.ParentWeb.Update();
I have done some googling on the issue, and can see that other people have had 
different issues with SP 2010 and Office 2003, but nothing that definitively 
states there is an issue loading these files programmatically (and setting CT 
and metadata).
I have been able to quite happily load the file manually, and set CT and 
metadata.
I suspect the properties in the DOC files are promoting and overwriting the 
values set against the item by the tool, but cant find anything to prove this 
(no additional versions in history etc).
Whilst I could convert the DOCs to DOCXs, as these are legal documents, I 
suspect there will be restrictions in place that they must be unaltered.
Has anyone suffered anything similar? Any solutions/code samples would be 
greatly appreciated
Cheers,
Nigel ___
ozmoss mailing list
ozmoss@ozmoss.com
http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss


Re: Issues Uploading Office 2003 docs to SP 2010 Programmatically

2013-05-14 Thread Web Admin
Nigel,

In my experience you need to set the properties before adding the file,
which your commented code was already doing.

Did that not work for you?

Regards,

Paul


On 15 May 2013 13:55, Nigel Witherdin nigel_wither...@hotmail.com wrote:

 Ok - have come up with a kludge of a fix.

 I upload the file, get the item, set the content type, set all the
 metadata then get the item again and set the content type again. This time
 the content type setting seems to stick.

 Yay - only took a few additional round trips to the database to re-get the
 item, re-set the content typemaybe not so yay after all

 Oh well, at least it works now ;)


 --
 From: nigel_wither...@hotmail.com
 To: ozmoss@ozmoss.com

 Subject: RE: Issues Uploading Office 2003 docs to SP 2010 Programmatically
 Date: Wed, 15 May 2013 02:15:18 +


 I thought setting the ParserEnabled to false would prevent any property
 promotion/demotion. See -
 http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spweb.parserenabled.aspx
  and
 http://sharepointserver-2007.blogspot.com.au/2012/04/sharepoint-spweb-property-parserenabled.html

 But unfortunately, Office 2003 docs are still ruining my day



 --
 From: is...@exd.com.au
 To: ozmoss@ozmoss.com; conrad.grob...@gmail.com
 Subject: RE: Issues Uploading Office 2003 docs to SP 2010 Programmatically
 Date: Wed, 15 May 2013 01:05:55 +

  Promotion of properties is my daily nemesis these days. I share your
 pain.



 In the past I used to overcome this by uploading using the frontpage RPC –
 which allows you to set the promoted properties in XML before sending it to
 the site. However, it is cumbersome to use, and the object model should do
 what it is told!









 [image: Description: Description: C:\Users\Brian\Pictures\EXD
 Logos\Extelligent logo no text.jpg]*Ishai Sagi* | Solutions Architect
 0488 789 786 | is...@exd.com.au | www.sharepoint-tips.com | 
 @ishaisagihttp://twitter.com/ishaisagi
 | MVP Profile https://mvp.support.microsoft.com/profile/Ishai



 *From:* ozmoss-boun...@ozmoss.com [mailto:ozmoss-boun...@ozmoss.com] *On
 Behalf Of * Nigel Witherdin
 *Sent:* Wednesday, 15 May 2013 10:37 AM
 *To:* OzMoss; Conrad Grobler
 *Subject:* Issues Uploading Office 2003 docs to SP 2010 Programmatically



 Hi All,



 We are using an in-house developed tool to upload files from old DMS into
 SharePoint 2010, and are finding we are having issues with Office 2003
 docs. The tool uploads the file, sets content type, and then set metadata
 (as read from a CSV). This all works fine for PDFs, DOCXs, etc. but it does
 not work with DOCs. Frustratingly, it doesn't report any errors, and the
 logging info looks just fine for these files.



 Instead of being set to the specified content type, they are always set to
 the default content type of the library, and do not have the metadata
 values set as expected.



 The code being used to upload the file and set the content type (both ways
 it has been tried) is:



 targetList.ParentWeb.ParserEnabled = false;

 targetList.ParentWeb.Update();



 //Hashtable ht = new Hashtable();



 //ht.Add(ContentTypeId, targetCt.Id.ToString());

 //ht.Add(ContentType, targetCt.Name);



 //SPFile file = targetFolder.Files.Add(filename, fs, ht, true);

 //file.Update();



 SPFile file = targetFolder.Files.Add(filename, fs, true);

 file.Update();

 file.ParentFolder.Update();



 file.Item[SPBuiltInFieldId.ContentTypeId] = targetCt.Id;

 file.Item[SPBuiltInFieldId.ContentType] = targetCt.Name;

 file.Item.UpdateOverwriteVersion();



 targetList.ParentWeb.ParserEnabled = true;

 targetList.ParentWeb.Update();



 I have done some googling on the issue, and can see that other people have
 had different issues with SP 2010 and Office 2003, but nothing that
 definitively states there is an issue loading these
 files programmatically (and setting CT and metadata).



 I have been able to quite happily load the file manually, and set CT and
 metadata.



 I suspect the properties in the DOC files are promoting and overwriting
 the values set against the item by the tool, but cant find anything to
 prove this (no additional versions in history etc).



 Whilst I could convert the DOCs to DOCXs, as these are legal documents, I
 suspect there will be restrictions in place that they must be unaltered.



 Has anyone suffered anything similar? Any solutions/code samples would be
 greatly appreciated



 Cheers,



 Nigel

 ___ ozmoss mailing list
 ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss

 ___ ozmoss mailing list
 ozmoss@ozmoss.com http://prdlxvm0001.codify.net/mailman/listinfo/ozmoss