my blog RSS 2.0
 Tuesday, May 25, 2004
 
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

Tuesday, May 25, 2004 5:02:00 PM (GMT Standard Time, UTC+00:00)  #    Comments [7] -

Friday, February 25, 2005 11:35:41 AM (GMT Standard Time, UTC+00:00)
hi..
<br>Have read both you blog and the ms-article and various sources. Before I commence on developing I would like to ask you if I have understood the situation correctly. The above + ms article would programmatically allow me to check out documents and save the back in again?. Or can I only create new documents.
<br>
<br>Regards
<br>mb, gwes
<br>
gwes
Friday, February 25, 2005 11:35:42 AM (GMT Standard Time, UTC+00:00)
As I remeber it, the code in the article is for creating new documents. However it is a demonstration of how to write your own web service to expose the functionality of the WSS object model. I believe there are already web services included with WSS that allow you to do check-out and check-in.
<br>
<br>Rohan
Rohan Cragg
Friday, February 25, 2005 11:35:42 AM (GMT Standard Time, UTC+00:00)
Thank you. Regarding the check out and in. I am currently working on with that functionality. It offers me checkin, checkout and uploaddocument. How ever documentation is hard to come by and I have not got it to work.
<br>
<br>I am rather confused regarding the functionality of these functions. Checkout gives me the document in binary form, works fine and I can check in the document successfully. But checkin does not offer me any parameter to submit a document. So I thought the upload function could be used, i.e.
<br>checkout, upload, checkin;
<br>
<br>WebServiceGUI.sFiles.SPFiles files = new WebServiceGUI.sFiles.SPFiles();
<br>byte[] rawFile = files.CheckOut( &quot;<a target="_new" href="<a target="_new" href="http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;">http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;</a>"><a target="_new" href="http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;">http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;</a></a> );
<br>
<br>rawFile[0] = (byte) 'M';
<br>rawFile[1] = (byte) 'B';
<br>string strResult = files.UploadDocument( &quot;AssemblyInfo.cs&quot;, rawFile,&quot;<a target="_new" href="http://dave:91/sox/Shared%20Documents/&quot;">http://dave:91/sox/Shared%20Documents/&quot;</a> );
<br>
<br>The upload function returns the following error string &quot;Value cannot be null.Microsoft.SharePoint&quot;
<br>
<br>files.CheckIn( &quot;<a target="_new" href="<a target="_new" href="http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;">http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;</a>"><a target="_new" href="http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;">http://dave:91/sox/Shared%20Documents/AssemblyInfo.cs&quot;</a></a>, &quot;update&quot; );
<br>
<br>The application I am writing is supposed to run on the server machine, what Iam trying to accomplish is to scan over all the documents in a library, and collect and some data and pending on the data change a set of values.
<br>
<br>Any ideas of what I am doing wrong or alternative solution
<br>
<br>mb, gwes
<br>
gwes
Friday, February 25, 2005 11:35:43 AM (GMT Standard Time, UTC+00:00)
ps. My credentials are set in the Reference.cs file
<br>
<br>many thanks
gwes
Friday, February 25, 2005 11:35:43 AM (GMT Standard Time, UTC+00:00)
From your code it does not appear that you are following the example in the article. My original post was simply pointing out that the article had a partial syntax error. If you follow the article fully you should be able to get this to work no problem. I'm afraid I don't have time to anaylse your code. I suggest you read the article carefully and download the sample code and start from there.
<br>
<br>Good luck.
Rohan Cragg
Friday, February 25, 2005 11:35:43 AM (GMT Standard Time, UTC+00:00)
Hi there.
<br>
<br>Have you tried this with a word xml document?
<br>
<br>I have used this method in the past quite successfully for various file types, but recently I have had to upload word xml docs and the filestream class is sticking an invalid ascii char at the end of the xml. ( a box)
<br>
<br>i.e. &lt;/w:worddocument&gt; &quot;box&quot;
<br>
<br>this causes word to gen an error because of invalid xml.
<br>
<br>Any idea how to get rid of that?
Manuel
Friday, February 25, 2005 11:35:44 AM (GMT Standard Time, UTC+00:00)
Did you have to change any security settings to get the file upload web service to work? I've followed the example from MSDN and accounted for the changes you've highlights in red, however I always get a &quot;The request failed with HTTP status 401: Unauthorized. &quot; error. I'm wordering if this is a code access securfity issue with the Sharepoint dlls, or a matter of passing in the correct user permissions so that Sharepoint can verify that the user calling the web service has rights to write to the specified document library. Anyone has any thoughts along these lines?
Mike Bruner
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)