cancel
Showing results for 
Search instead for 
Did you mean: 

Accessing external files thorugh sap

Former Member
0 Kudos

Hi there,

what I want to do is have a text file that contains information particular to that machine.

My Add on will read this when loading up to access the information is this possible and how would i add it?

I have tried hard coding it to C:\config.txt but the add doesnt seem to like an external file?

Any ideas.

Accepted Solutions (0)

Answers (1)

Answers (1)

former_member201110
Active Contributor
0 Kudos

Hi Matthew,

You don't mention what development language you are using. As far as I know, if you are using .NET then you could use the FileStream object to read/write to a text file (see MSDN for full details at http://msdn2.microsoft.com/en-us/library/system.io.filestream(VS.80).aspx).

Perhaps you could post an example of the code you are using?

Kind Regards,

Owen

Former Member
0 Kudos

Yes i'm using VB.NET, all i need is to read in three lines form a text file like so. This works as i've run it through the debugger, however SAP doesnt seem to like it when i add my program as an add on.

Try

Dim objReader As IO.TextReader = System.IO.File.OpenText("D:\SAP\Config.txt") 'easier to put in with other program then not set path

config1 = objReader.ReadLine

config2 = objReader.ReadLine

config3 = objReader.ReadLine

objReader.Close()

Catch ex As Exception

SBO_Application.MessageBox("There is a problem with the configuration file: " + vbCrLf + ex.Message)

End Try

Also rather than have a hardcoded path i would rather have something like .\config to make it more flexible is this possible?

Matt

Former Member
0 Kudos

Hi!

There is no problem with B1 when reading files or... doing smth

Try StreamReader.

This is my C# example how to read lines and add elements, split by "\t" to the arrays.

StreamReader sr = new StreamReader(termTransDir + termTransferFileName);

while (sr.Peek() >= 0)

{

string itmLine = sr.ReadLine();

ArrayList arrItem = new ArrayList();

arrItem.AddRange(itmLine.Split('\t'));

arrTransItemCodes.Add(arrItem[0]);

arrTransItemNames.Add(arrItem[1]);

arrTransItemEANs.Add(arrItem[2]);

arrTransItemSerials.Add(arrItem[3]);

arrTransQty.Add(arrItem[4]);

}

sr.Close();

hth!

Former Member
0 Kudos

thanks for the reply i've managed to get the file to read in now as an addon. however rather than having it hardcoded is there a way of having the it read the file in repect of where the file is? for example ./Config.txt?

do you know where it stores the root?

thanks Matt.

Former Member
0 Kudos

If i've understood u right, you wanna have a root of your AddOn?

If so, it's like that:

string filepath = Application.StartupPath + "
";

if (File.Exists(filepath + "Config.txt"))

{

// proceed your actions

}