in

SharePoint Blogs

The Best Place for SharePoint-related Blogs

rcragg's blog

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

Comments

 

Iverson 3 said:

What do you pass in for

targetFolder?

August 1, 2007 7:01 AM

Leave a Comment

(required )  
(optional )
(required )  
Add

Need SharePoint Training? Attend a SharePoint Bootcamp!

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