on 01-18-2007 11:50 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
// обновляем данные на форме
Freeze(true);
LoadData();
Freeze(false);
Update();
}
else
{
throw new SAPAddons.Exceptions.SBOException("");
}
}
}
catch (Exception ex)
{
owner.SendError(ex);
}
threadGetFile = null;
}
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
6 | |
6 | |
4 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.