Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Trying to upload document programatically

  Asked By: Brenda    Date: Feb 28    Category: Sharepoint    Views: 1114

I tried to upload a document in a workspace document folder using
CreateDocument function from the SPS SDK sample "adapted" to VBscript.

When I launch the function I get the following error (on the line which
contains "oStream.LoadFromFile sFilestream"):

Error Type:
ADODB.Stream (0x800A0BBA)
File could not be opened.

Does anybody know which is the problem?

The code is the following:


'/// <summary>Import document on server</summary>

'/// <param name="sFileStream">Path of the file to be uploaded</param>

'/// <param name="sHref">New document's URL</param>

'/// <param name="sCC">Document's content class </param>

'/// <returns>The created document object</returns>

Function CreateDocument(sFilestream, sHref, sCC)

Dim oDoc

Dim oStream

Dim nIndex

Dim sPropName

Set oDoc = CreateObject("CDO.KnowledgeDocument")

Set oStream = oDoc.OpenStream

oStream.Type = 1


oStream.LoadFromFile sFilestream


If sCC <> "" Then

oDoc.ContentClass = sCC

End If

oDoc.DataSource.SaveTo sHref, , , adCreateOverwrite

Set CreateDocument = oDoc

End Function




1 Answer Found

Answer #1    Answered By: Kristan Benjamin     Answered On: Feb 28

The following code  is working for me :

on error  resume next
const adModeRead = 1
Const adModeReadWrite = 3
Const adFailIfNotExists = -1
Const adCreateNonCollection = 0

'set oVer = CreateObject("CDO.KnowledgeVersion")
'oVer.CheckOut neve
'Set oVer = Nothing
ido=replace(ido," ","-")
neve="http://myserver/oper/Documents/Groups/rendszerstatisztika/myserver" & ido
& ".csv"
set oKD = CreateObject("CDO.KnowledgeDocument")
oKD.DataSource.Open "http://myserver/teszt/Documents/Test_here",Nothing,
Set Stream = okd.OpenStream
Stream.LoadFromFile "D:\devel\properties\myserver.csv"
Set Stream = Nothing
okd.DataSource.SaveTo neve, , , adCreateOverwrite
set okd=nothing
set oVer = CreateObject("CDO.KnowledgeVersion")
oVer.Checkin neve
oVer.Publish neve
Set oVer = Nothing

Didn't find what you were looking for? Find more on Trying to upload document programatically Or get search suggestion and latest updates.