cancel
Showing results for 
Search instead for 
Did you mean: 

OpenFileDialog

Former Member
0 Kudos

Hello,

I have been seeing all post on OpenFileDialog and there are things that I do not understand.

I have SBO 2005 and VB.NET 2005, I have proven all the codes that I have found in post and does not work and to me it continues appearing the damn error :

""Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.

Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised

if a debugger is attached to the process.""

Does it work to somebody OpenFileDialog or somebody knows like doing it?

THANKS, VERY THANKS

pMa

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi pedro!

You have to attribute you main method with the STAThreadAttribute to make this things work. Just google it, its just a line of code you have to put before your main() method.

Hope it helps;

Jon Arranz

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi,

Since your using vb.net, you can use the OpenDialog components and just copy the path\directory and save it in your string variable.

rasmuswulff_jensen
Active Contributor
0 Kudos

We have the same problem... It has something to do with the debugger in .Net 2.0... If you start the add-on without debugging (CTRL+F5) the problem does not happen...

Former Member
0 Kudos

HI~

I have the same problem in vs 2005...

I can't find solution.

I have try the code like this "<STAThreadAttribute()> Public Sub Main()

Dim Thread1 As New System.Threading.Thread(AddressOf Main)"

Thread1.SetApartmentState=STA"

But it didn't work.

In vs 2005 I can't do this

"Dim Thread1 As New System.Threading.Thread(AddressOf OpenFileDialog1.ShowDialog) "

But It still have solution in vs.net 2003....

In vs.net 2003 OpenFileDialog works with SBO SDK well.

So.. if you have the same problem, you can use .net 2003 to solve it

And if you have solution in vs2005(vb script...) please show your solution

Think you very much

have a nice day

Former Member
0 Kudos

hi, this code works fine in vs2005:

void MainForm_OnFormEvents(string FormUID, ref SAPbouiCOM.ItemEvent pVal, out bool BubbleEvent)

{

if (pVal.EventType == SAPbouiCOM.BoEventTypes.et_ITEM_PRESSED && pVal.ItemUID == "btSel" && pVal.BeforeAction == true)

{

if (Mode == SAPbouiCOM.BoFormMode.fm_OK_MODE)

{

SelectFiles();

}

}

}

public void SelectFiles()

{

using (GetFileNameClass oGetFileName = new GetFileNameClass())

{

oGetFileName.Filter = "txt files (.txt)|.txt|All files (.)|.";

oGetFileName.InitialDirectory = "c:
";

Thread threadGetFile = new Thread(new ThreadStart(oGetFileName.GetFileName));

<b>threadGetFile.SetApartmentState(ApartmentState.STA);</b>

try

{

threadGetFile.Start();

while (!threadGetFile.IsAlive) ; // Wait for thread to get started

Thread.Sleep(1); // Wait a sec more

threadGetFile.Join(); // Wait for thread to end

// Use file name as you will here

owner.fileName = oGetFileName.FileName;

if (owner.fileName != string.Empty)

{

Classes.LoadReg lr = new LoadReg(owner, owner.fileName);

if (lr.IsRegFile())

{

owner.regItems = lr.GetRegItems();

LoadRegItemsList(owner.regItems);

// &#1086;&#1073;&#1085;&#1086;&#1074;&#1083;&#1103;&#1077;&#1084; &#1076;&#1072;&#1085;&#1085;&#1099;&#1077; &#1085;&#1072; &#1092;&#1086;&#1088;&#1084;&#1077;

Freeze(true);

LoadData();

Freeze(false);

Update();

}

else

{

throw new SAPAddons.Exceptions.SBOException("");

}

}

}

catch (Exception ex)

{

owner.SendError(ex);

}

threadGetFile = null;

}

}

Former Member
0 Kudos

I don´t find the solution for a VB.2005. i am working in a VB.2003.

But IF somebody know make it in VB.2005.....jejeje.

THANKS to all.

Former Member
0 Kudos

Hi,

I'm use C# .2005 and i have not any problems with follow code

GetFileNameClass oGetFileName = new GetFileNameClass()

Thread threadGetFile = new Thread(new ThreadStart(oGetFileName.GetFileName));

<b>threadGetFile.ApartmentState = ApartmentState.STA;</b>

....

i am think in VB.2005 it will be same

Former Member
0 Kudos

Hi Pedro,

Again, try creating an EditText and bind with a field with type general and structure link. Then "double-click" into the EditText item that has been bound to the UDF.

HTH,

Ian

Message was edited by:

Ian Defilippi

Former Member
0 Kudos

THANKS to answer jJON.

In my main method I have:

Module mInicio

Public oSBOEvents As cSBOEvents

<STAThread () > _

Public Sub Main ()

'crea la instancia de la clase SBOEvents

oSBOEvents = New cSBOEvents

'captura de eventos de SBO

System.Windows.Forms.Application.Run()

End Sub

….but it follows without working.

I have been seeing and proving your code, and are things that not where to put it, like:

Declare Auto Function FindWindow Lib "user32.dll" (ByVal class As String, ByVal name As String) As IntPtr

Declare Auto Function SetForegroundWindow Lib "user32.dll" (ByVal hwnd As System.IntPtr) As Integer

Former Member
0 Kudos

Hi Pedro,

Have you looked at

All you need is standard SDK.

HTH,

Ian