in order to use the FolderBrowserDialog control in asp.net, i had to add a reference to System.Windows.Forms in my project.
i wrote this code:
FolderBrowserDialog f = new FolderBrowserDialog();
f.ShowDialog();
but this error occured:
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.
any help?
If you're trying to use this control in an ASP.NET application, you're going to be sadly disappointed.
You can't use WinForms controls on ASP.NET Pages. You should check out the FileUpload control instead (it will allow your users to pick a file and upload it to the site).
If you're actually building a WinForms application (not ASP.NET), then the fix is quite easy (and you should fix your question and tagging):
public static void Main()
Becomes:
[STAThread]
public static void Main()
Keep in mind though, Visual Studio usually adds this to your generated code when you create a WinForms project.
You cannot use Windows Forms controls in ASP.NET. And in fact using the FolderBrowserDialog from ASP.NET doesn't make a lot of sense, since it is a webpage. Web applications can't get direct access to a user's filesystem. If you want to get a file from the user you should use a FileUpload control.
Related
I have a carefully formatted report in Access 2013 and I'm trying to create a UI that will print this report upon a button click. I would be open to a C# WPF or Form app or perhaps an HTML page that could contain this button.
Does anyone know if this is possible and if so what the code would be?
My end goal is to have the user be able to print this report without having to access the database directly. I am open to other languages/platforms.
At the end of the day you still need Access installed, and at the end of the day you still have to launch Access, and at the end of the day you still 100% relying on Access.
Thus to print an Access report you still have to launch Access. It not at all clear why then you cannot built your required UI in Access since you still 100% relying on Access for this report.
You thus will have to automate Access and rely on Access. You can use any system or language that supports COM object automation.
So in say windows scripting, you could go:
Dim app As Object
Set app = CreateObject("access.application")
app.OpenCurrentDatabase ("path to database")
app.DoCmd.OpenReport ("ReprotName")
app.CloseCurrentDatabase
app.Quit
The above same code would work in vb.net. Note that the “default” to open the report will send it to the printer without preview.
Also keep in mind that since you are creating an instance of the Access application, then all of the startup code and forms will launch and run. If such startup code and the startup form being run requires ANY user interaction, then the above will not work. Because of the above “many” issues, you likely best create an application that has linked tables to the data, and contains your required report. This approach will thus avoid all of the existing application code and startup forms running.
So in any case you WILL have to launch the application and deal with all of the startup forms etc. As noted, often then it makes sense to copy out the report to a separate application with linked tables for your purpose.
Keep also in mind that the Access runtime (as opposed to full version) does not support nor allow use of CreateObject - you have to resort to shell() with startup parameters to launch + run the report.
Last but not least, you can from the Access UI simply DRAG the report to your desktop. The result is a one click button on your desktop that will launch the report in question.
I wrote a C# program that works good.
I want to execute that project, in a website, so the main form of my project will be in the web form.
I tried this code in the web application webform:
protected void Page_Load(object sender, EventArgs e)
{
Program.Form1 y = new Program.Form1();
y.ShowDialog();
}
and it works, but my program does not appear in the website, but in another window, and the website stays empty and in continuous linking trial condition.
How can I insert my program into the website window?
What you are calling a "C# Project" is a Windows Forms project. It it not compatible with ASP.NET. You cannot run it that way.
Read about ASP.net, its a tool to develop websites with C#. Programs and websites are 2 different things and you can't run your program in a website. For example, you can't run games in your browser because it is written differently.
Read about it, its very simple to use.
The code in your projects is using the same language (in your case, C#, but it could also be VB) but WinForm applications and Web applications are two different things. The make a long story short, the user interface of the first one will be Windows application installed on a machine while the second one will be displayed in a browser (and hosted on a web server). The bottom line is that those project type cannot be mixed.
However, if you want to reuse some of your code in a Web or a WinForm application, you should consider creating a library project. You'll be able to manage all the code that doesn't refer to specific UI from there and you'll be able to reference it from both of your projects.
I just implemented drag&drop in my application. It goes two ways:
From my app to Windows Explorer: exports files
From Windows Explorer to my app: imports files
One side effect is that I can also drag files from my application to my application (the same window), which is not intended.
Is there a elegant way to make sure, that a drag&drop operation I started won't be accepted by my application? E.g. check if the source of the drop operation != my application?
You need to register the fact that you initiated a drag from inside your application with some sort of facility or service. If you receive a drop on your application, ask the facility/service if the drag was initiated within your application. If so, discard. Reset the facility/service afterwards (in any case).
I just figured out a way to do this.
Now I set two types of data on my drag&drop data object:
The file names I want to export
A Unicode-Text object containing the name of my application
In my Drop-handler I check if a Unicode-Text object is present and if it contains my application's name. If so, I abort the drop operation.
I'm making an Autocad Plugin which runs fine using Windows Forms
And I've created a user control (winforms) to replicate in any form I like in the future.
The question is
From the control's code, how do I get the instance of the application running that control?
(Probably a pure winforms problem)
Coditions:
Within the plug-in I can get the Autocad Application instance with no
problem.
This user control is meant to be in a separate assembly (dll) to be referenced in the plug-in application, so it has no direct access to the application instance.
A little explanation about the scenario:
There's a Main Assembly being run by Autocad as a plug-in.
That assembly has the Autocad application instantiated.
Now I have some useful form controls to work with Autocad, and they are in a separate assembly. (That's because I want to use them in as many different plug-ins I like).
So, Autocad runs main assembly, and main assembly runs controls of the separate assembly.
In order to work properly, those controls need to have access to the Autocad application wich is running the main assembly.
Today I use the application as a property in the controls, wich I must set before working with them. (If I forget to set that, exceptions are raised). Since I cannot have a control with a creator taking parameters.
I want the controls to detect their running application so I avoid that workaround.
Please see the following code
public class MyCommands {
[CommandMethod("NS", "TEST", "TEST", CommandFlags.Modal)]
public void TestCommand() // This method can have any name
{
Form fromAutoCADAPI = new TestForm();
Form independent1 = new TestForm();
Form independent2 = new TestForm();
//Using AutoCAD application
Autodesk.AutoCAD.ApplicationServices.Application.ShowModelessDialog(fromAutoCADAPI);
independent1.Show();
independent2.Show();
//Using Windows Forms Application
var count = System.Windows.Forms.Application.OpenForms.Count; //should be 3
Autodesk.AutoCAD.ApplicationServices.Application.ShowAlertDialog(count.ToString());
}
}
If this is what you already know, then may be you should paste some sample code that will help understand where specifically you are stuck in your code. This is the way I have used AutoCAD application and Windows Forms application. In case you wan't to grab WPF application then you can use
var application = System.Windows.Application.Current;
Hello and thank you for looking.
Problem Description:
I have implemented a c# WinForm application with the browser control embedded and have implemented IInternetSecurityManager to perform the tasks we need in order to allow cross-domain access in iframes with our locally installed web pages.
All things are working as expected with IInternetSecurityManager, IOleClientSite, IDocHostShowUI and IDocHostUIHandler. In other words, we are being called by the browser control for all of our implementations.
The problem is when the web page loaded in the browser control has script that calls window.showModalDialog(): The browser control instance that is being used no longer communicates with our client site. Absolutely no QueryInterface calls or any other methods are called in any of the interfaces mentioned above.
The document in the dialog is not using our security manager implementation I am assuming because the web browser control in the dialog that IE displays is not the same one we called SetClientSite() on.
Question:
How do we talk to this new browser control? We need to be able to give the browser control in the dialog that is shown by IE, our IInternetSecurityManager implementation. But, we never get the opportunity to tell it about our client site to make the hook up, so to speak. In other words, there is no communication from IE that tells us via an interface that says, "I am a new browser control created by IE and here is my IUnknown interface. This your chance to set my client site, etc." We would be golden if there was such a notification coming from IE.
The result is two different security contexts are being used and our applicaiton fails any time we are in a dialog using an iframe, because our IInternetSecurityManager implementation is not in use.
Example Source Code:
I have chiseled away at source code to protect the innocent :) and have reduced down to something I think you can work with in its own Visual Studio 2010 solution.
Please read the ReadMe.txt file for information on the problem, repro steps, etc.
The test web pages I wrote display information and steps to guide you through the use of the sample.
Please let me know if you have questions about what I am trying to accomplish or if the sample isn’t clear enough.
Please advise. Thank you.
http://home.comcast.net/~lowrider2112/bin/TestIEHost.rar
You can override the web-browser's control method CreateWebBrowserSiteBase.
protected override WebBrowserSiteBase CreateWebBrowserSiteBase()
{
return new ExtendedWebBrowserSite(this);
}
and implement ExtendedWebBrowserSite like this:
class ExtendedWebBrowserSite : WebBrowser.WebBrowserSite,
IDocHostShowUI,
IfacesEnumsStructsClasses.IServiceProvider,
IInternetSecurityManager
...
That can call the class IInternetSecurityManager.
One option would be to create your own dialog form (in C#) with another custom-security WebBrowser control on it. Then you can call from Javascript to C# to open the form instead of using showModalDialog.