Import text file - privileges problem?

I’ve only seen a couple of oblique hits hunting for this problem here so, does anyone understand this problem? I ripped off the Stream example from the help, to read in a quasi-structured text file. I want one Notes Doc per line in the file, and it’s not very helpfully laid out - partly structured, partly not: so using “Import” is out.Anyway; stole the LS Stream Read example from the help. It won’t work: continually says the stream has 0 bytes, or it can’t open the file. Foudn the stuff about making the agent privileged enough: makes no difference. Converted from Stream to good old Open For Input as File # - no difference. Tried smaller files (input is 10Mbytes): no difference. Wondered if it was a problem with the agent changing from unprivileged to privileged, so made a new blank agent… no difference.

Tried on a completely different network; the thing runs straight away! Packaged up that version in a bare db and brought it to the network with the (apparent) problem - where it doesn’t work.

I’m administrator in all possible ways on both networks: is this an ECL problem? Is it because on the non-working setup I am referring to something other than drive C? What the hell is goin’ on?

Subject: import text file - privileges problem?

Here’s an example to use when importing a quasi-structured file on a local system. The code using body.appendtext, but you could change it to only write one line. Maybe this will help!

===================================

On Error Goto errorhandler

Dim session As NotesSession

Dim db As NotesDatabase

Dim dc As NotesDocumentCollection

Dim doc As NotesDocument

Dim stream As NotesStream

Dim pathname, IDHolder As String

'pathname = "C:\CTP.txt"

pathname = Inputbox("Enter path...", "Example, c:\ctp.txt")



Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

Set stream = session.CreateStream



pathname = pathname 

If Not stream.Open(pathname, "ASCII") Then

	Messagebox pathname,, "Open failed"

	Exit Sub

End If



If stream.Bytes = 0 Then

	Messagebox pathname,, "File has no content"

	Exit Sub

End If

CreateAnother:

Set doc = New NotesDocument(db)

Call doc.ReplaceItemValue("Form", "CTP")

doc.CTPID = IDHolder

Dim body As New NotesRichTextItem(doc, "CTPs")

counter% = 0



Do

	counter% = counter% + 1

	'Call body.AppendText("[LINE " & counter% & "] ")

	'Call body.AppendText(" ")

	sLeft = Left (buffer$, 2)

	sLeft2 = Left (buffer$, 7)

	sRight = Right (buffer$, 7)

	

	If sLeft = "ID" Then

		doc.CTPID = sRight

		If IDHolder = "" Then

			IDHolder = sRight

		End If

	End If

	

	If sLeft2 = "*** NOT" Then

		Checker = Left(buffer$, 24) 

	End If

	

	If Left(buffer$, 7) = "*** NOT" And Left(buffer$, 24) <> Checker And doc.CTPTask(0) <> "" Then

LetsSave:

		doc.CTPTask = Checker

		Call doc.save(True, True)

		Goto CreateAnother	

	End If

	buffer$ = stream.ReadText(STMREAD_LINE, EOL_CRLF)

	

REM Discard lines with only LF + CR

	While buffer$ = Chr(13) & Chr(10) _

	And (Not stream.IsEOS)

		buffer$ = stream.ReadText(STMREAD_LINE)

		sLeft = Left (buffer$, 7)

	Wend

	

	If Checker <> "" Then

		If sLeft = "*** NOT" And Left(buffer$, 24) <> Checker Then

			Goto LetsSave

		End If

	End If

	

	If sLeft = "*** NOT" And doc.CTPTask(0) = "" Then

		doc.CTPTask = buffer$

		Call body.AddNewLine( 1 )

	End If

	

	Call body.AppendText(buffer$)

	

Loop Until stream.IsEOS

Call stream.Close

doc.CTPTask = Checker

Call doc.save(True, True)

errorHandler:

'Messagebox "Error in " & Err() & ": " & Error()

Exit Sub

Subject: and a few hours later…

I tried this, suitably hacked around to remove things like the string checking and stabilise it for my fieldnames. It still stops on the “stream has no content” check - so the stream open succeeds but doesn’t report the attributes of the file associated with the stream.

PS: goto statements! I can feel the goosebumps a-risin’!

Subject: RE: and a few hours later…

Did you have any luck? And yes, the GoTo lines will certainly send chills up the down the spin of some Developers!!

Subject: RE: import text file - privileges problem?

thanks ten thousand times over for that - I will have a go as soon as I deal with the small problem of someone (apparnetly) deleting 15,000 documents where they shouldn’t have been allowed…

To be clear: the file I am reading is on the local drive of the client PC. This machine has 2 volumes on one 120Gb disk - drive C & drive E.

Subject: import text file - privileges problem?

Do you have rights to run unrestricted agents on the server? (Just because you are an administrator doesn’t make it so.) An unrestricted agent is one that, among other things, performs direct file access to the system.

Subject: RE: import text file - privileges problem?

I should have said - this agent is on a client. I have mostly R5 databases on a mixture of R5.0.12 and 6.5.1 servers: this particular database is a completely blank virgin templateless testbed, created totally fresh on 6.5.1 client, stored on a 6.5.1 server, and running code on the client, reading the client PC’s E drive. Or rather, refusing to read it. The client is XP SP1, logged in to a domain, and my account is a member of Domain Admins group: I can read n write to the local drives like a mad thing from other applications.

Just not from this agent!

Subject: import text file - privileges problem?

If the file to import is on the client will the agent work?