my blog RSS 2.0
 Friday, May 28, 2004

Dim targetWeb As SPWeb = SPControl.GetContextWeb(Context).Webs.Item("sites/IT")
Dim docLib As SPDocumentLibrary = CType(targetWeb.Lists.Item(New Guid(targetFolderGUID)), SPDocumentLibrary)
Dim docLibFile As SPFile = docLib.RootFolder.Files.Add(fileName, fileContents)
Dim docItem As SPListItem = docLibFile.Item
docItem.Fields("Category") = "General"

If I attempt to set the value of a field (i.e. a Column) in a List, the complier complains that:

Property 'Item' is 'ReadOnly'

Anyone know why I shouldnt be allowed to do it this way?!


UPDATE: the following code is what I was looking for...

docItem("Category") = "General"
docItem.Update()

Friday, May 28, 2004 8:01:00 PM (GMT Standard Time, UTC+00:00)  #    Comments [5] -
SharePoint
Friday, February 25, 2005 11:35:39 AM (GMT Standard Time, UTC+00:00)
Rohan Cragg
Friday, February 25, 2005 11:35:39 AM (GMT Standard Time, UTC+00:00)
Strange, almost seems like a VB problem. 'ReadOnly' on a property causes all of the properties of that item to also be read only? Obviously 'Item' itself needs to be read-only since it doesn't make sense to change the item that corresponds to the file, but there's no reason that editable fields on the item should be read-only.
<br>
<br>Have you tried doing it in C#?
JD
Friday, February 25, 2005 11:35:40 AM (GMT Standard Time, UTC+00:00)
Thanks JD, you're kinda right. Not knowing C# very well this was daunting for me but it inadvertantly led me to the answer! The following works fine:
<br>
<br>docItem[&quot;Category&quot;] = &quot;General&quot;;
<br>docItem.Update();
<br>
<br>docItem(&quot;Category&quot;) = &quot;General&quot;
<br>docItem.Update()
<br>
<br>This feels wrong because I felt like this syntax meant that I was replacing the SPList object (whose name is &quot;Category&quot;) with an Object = &quot;General&quot;.
<br>
<br>Why does the object model let you do it this way, and not the way I was trying?! Weird... but I'm happy now!!!
Rohan Cragg
Friday, February 25, 2005 11:35:40 AM (GMT Standard Time, UTC+00:00)
My brain completely glossed over the fact you were calling the fields accessor instead of the implicit value accessor because I knew what you were trying to do.
<br>
<br>Sometimes approaching the problem from a different direction, even if it's the wrong one, gets you there in the end. :)
<br>
<br>
JD
Friday, February 25, 2005 11:35:40 AM (GMT Standard Time, UTC+00:00)
when the object has a object type property ,it always be seted readonly . because,it may easy to deal with o/r map .
Snowman
All comments require the approval of the site owner before being displayed.
Name
E-mail
(will show your gravatar icon)
Home page

Comment (Some html is allowed: a@href@title, strike) where the @ means "attribute." For example, you can use <a href="" title=""> or <blockquote cite="Scott">.  

Enter the code shown (prevents robots):

Live Comment Preview
Archive
<November 2008>
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2008
Rohan Cragg
Sign In
Statistics
Total Posts: 24
This Year: 0
This Month: 0
This Week: 0
Comments: 42
Themes
Pick a theme:
All Content © 2008, Rohan Cragg
DasBlog theme 'Business' created by Christoph De Baene (delarou)