in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

rcragg's blog

May 2004 - Posts

  • Why is SPListItem always ReadOnly?

    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()

  • Problems uploading documents with a custom web service

     
    It is supposed to allow me to upload a document into a library of my choice except that the document completely disappeared. The bit I was originally missing is now highlighted in red. I wish the article could have mentioned this, it would have saved me alot of time! The problem was that I was starting off in the root site 'myintranet:8099', and I wanted to access a document library in 'myintranet:8099/sites/it'. Even though I was supplying the GUID it couldnt find the list from the root web, I had to also tell it to move up to the 'sites/it' web before it would find it. Needless to say the documentation does not make this at all clear.
     
    However this still does not explain what happened to the documents that were being reported as being saved OK?!
     
    Now I want to set the value of a custom field (i.e. a Column) in this List, and I'm having trouble doing that too (see my other post). This is not a good week :-(

     
    Here's how it was supposed to work. The web service was registered OK, the client code calls the upload method sending the folder URL, the filename and the binary data, and the web service uses the SPFolder.Files.Add method to create the file. It appeared to do so because it then returns the SPFile.Title, and .TimeCreated properties correctly, however the document completely disappeared into the void and didn't appear in the list (nor in any other list that I could find either)!
     
    Here's (some of) the code:
     
    [WebMethod (UploadDocument)

    targetWebsite = SPControl.GetContextWeb(Context).Webs.Item("sites/IT")
    Dim
    folder As SPFolder = targetWebSite.GetFolder(targetFolder)
    Dim NewFile As
    SPFile = folder.Files.Add(fileName, fileContents)
    Return NewFile.Title + " created " + NewFile.TimeCreated.ToLongDateString()

    ]

    [Client code:

    DialogResult = OpenFileDialogUpload.ShowDialog()
    If DialogResult = DialogResult.OK Then

    sFilePath = OpenFileDialogUpload.FileName
    sFileName = sFilePath.Substring(sFilePath.LastIndexOf("\") + 1)
    Dim fStream As IO.FileStream = CType
    (OpenFileDialogUpload.OpenFile, IO.FileStream)
    Dim nBytes As Integer = CInt
    (fStream.Length)
    Dim binFile(nBytes) As
    Byte
    ' get the file contents into a buffer
    Dim nBytesRead As Integer
    = fStream.Read(binFile, 0, nBytes)
    ' send the document to sharepoint
    Dim spf As New
    SPFiles.SPFiles
    spf.Credentials = System.Net.CredentialCache.DefaultCredentials
    MessageBox.Show(spf.UploadDocument(sFileName, binFile, sDestination))

    End If

    This topic is currently active on a newsgroup thread

  • Connectable Page Viewer Web Part

    Currently watching this thread with great interest - I love the new Google Groups

    Great work guys, here's one person who's definitely interested in the final solution! ;-)

    respect to:
    Mike Walsh
    Bart Waeterschoot
    and Ian Morrish

    UPDATE: Respect also, of course, to Jim Duncan. Mads Nissen has also now posted his own solution


Need SharePoint Training? Attend a SharePoint Bootcamp!

Posts (c) their respective authors. Everything else (c) 2007 SharePoint Experts