How to instantiate a SaveFileDialog in a web application - asp.net

I am new to Visual Studio and ASP. I have a web application in which I need to use SaveFileDialog. When I open the Dialogs group in the toolbox, all the controls including SaveFileDialog are greyed out. Is there an alternative method? I notice that in the Standard group there is a FileUpload control but it is not matched by an equivalent FileSave or FileDownload.

The FileSaveDialog is a windows UI control that can be used when developing native Windows applications. They are not possible to use in web projects that are run in any browser on any device.
To save a file from the web browser you can use JavaScript as described in Javascript: Create and save file.

Related

Issue while using WinForm user Control in asp.net MVC applicaton

I need to use a WinForm User Control in an ASP.Net MVC4 application.
The control has been embedded using the object tag and classid attribute, but upon viewing the view in browser, only a blank frame is visible, without any cross-sign on top-left corner of frame. The viewing browser is on a machine with .Net Framework 4.5. Similar issue was faced in an ASP.Net application but same was rectified using Registry setting (EnableIEHosting = 1).
Kindly suggest.
Thanks.
Gitika
WinForms user controls are not intended to be used from an ASP.NET (MVC or not) application.
As you should already knows, ASP.NET generate HTML codes that will be sent to the browser when requested. The browser can run on a multitude of operating systems (OS). WinForms user controls essentially only run Under Microsoft Windows.
The second thing to know is that a browser run in a restricted environment and as such as a very limited access to the computer and its OS.
Since you are using ASP.NET MVC, then you should create a partial view that is similar to your user control if this is what you want. Also, another thing to know is that any logic behing your control need to be converted to JavaScript or jQuery. This is what browsers understand.

How to embed 3rd party DLL on the client side of ASP.NET Forms application

I am sorry for very lengthy introduction here but I want to explain my problem in details.
We have a 3rd party dll from one of our vendors that provides Silverlight-based user interface to their data.
We already use that dll in two different projects:
IE toolbar button that opens a UI window to that 3rd party data related to the currently displayed data on the webpage (another web application).
Windows application (.exe) that is called from another windows application when user pressed a particular key combintion (again passing parameters from that application).
We also have a working ASP.NET (forms) intranet application (in-house developed). Users of that application also want an easy access provided by that DLL. I need a solution for making it possible.
As we have corporate controlled environment we have .NET Framework, Silverlight, the toolbar and executable installed on users' machines and all web applications run in IE.
So far I was able to call the existing exe (that I mentioned in #2) and pass the parameters from my asp.net application as ActiveX (similar to what described here How to launch an EXE from Web page (asp.net)). It works but every time it gives that standard popup "An ActiveX control on this page might be unsafe...".
I also tried to create my own dll that wraps the 3rd party dll and embed it in my asp.net page using <object> html tag. It works too but also displays the same popup every time.
Here are my choices (in preference order):
Embed the UI provided by the 3rd party dll (possible wrapped in another dll) in existing page of my asp.net application (currently it opens a new window).
Call executable with parameters (as I do it now) but without annoying pop-up about ActiveX security.
Embed dll using <object> tag as a rich client side custom control.
Either way I don't want users to see the popup every time they go to the 3rd party application.
Is there any way to do it?
If object tag code ran effortlessly without participation from the user it would be a virus/malware delivery mechanism.
One way is to sign the activex object and then get all your machines to trust it, e.g.
Sign an ActiveX control for intranet usage?

Convert asp.net application to windows forms app

I have written and deployed an ASP.NET application that is pretty complex. It uses XSL transformations to create web forms for a large variety of data objects. The data comes from the database as XML via a web service.
Now, I need to create a Windows desktop application that will provide a small subset of the web applications functionality to a user who may not have access to the web (working in remote areas). I will provide the data syncing using the MS Sync Framework. And I will have the desktop use a local data store.
I would like to use the same xslt files in the desktop app that I use in the web app for the form creation so that, if changes are made, the desktop app can update itself when it connects and syncs its data.
But, I am wondering how to replicate the asp.net codebehind logic of my web app in the windows forms. If I use a browser control to render the XSLTransformation result, then how could I handle click events, etc, in the form? Also, can I launch other windows as "dialog boxes" from my windows forms (I do this in my web app using RadControls functionality)?
Thanks for any advice you can give.

How do I add a browse file system button to a Visual Studio app?

I am looking to add a browse button to a visual studio app something simular to the the dialog box in the 'fileupload' tool. I am looking to be able to graphically select any file from my computer or a computer across a network.
There is a FileUpload control...
http://www.dotnet-webhosting.com/aspnet-2-0-tutorials/asp-net-2-0-fileupload.aspx
Otherwise, the SWF uploader is very popular if you want something richer: http://www.swfupload.org/
EDIT:
The OpenFileDialog is a WinForms control and there is no equivalent in ASP.NET. When using a FileUpload the browser knows to provide you with a file picker to browse your local system. There is no way to replicate this behaviour with some type of local ActiveX control. This is a natural and deliberate limitation of the web, the application should not be able to access your local file system apart from in exceptional and well-defined circumstances.

Is it possible to add a web user control to a class library?

I'm looking at building some web user controls with an eye toward re-use, but I can't seem to add a Web User Control in my class library in VS2008. Is there a way to work around this problem, or is there a better approach to creating reusable controls?
You can create either Web User Controls or Web Custom Controls that encapsulate the functionality you need. The main difference between the two controls lies in ease of creation vs. ease of use at design time.
You should maybe consider creating a Web Custom Control library. There is a walkthrough for creating a web custom control using the Web Control Library template.
According to the MSDN article "Recommendations for Web User Controls vs. Web Custom Controls" these are the differences between the two types of controls:
Web user controls are easy to make,
but they can be less convenient to use
in advanced scenarios. You develop Web
user controls almost exactly the same
way that you develop Web Forms pages.
Like Web Forms, user controls can be
created in the visual designer, they
can be written with code separated
from the HTML, and they can handle
execution events.
However, because Web
user controls are compiled dynamically
at run time they cannot be added to
the Toolbox, and they are represented
by a simple placeholder glyph when
added to a page. This makes Web user
controls harder to use if you are
accustomed to full Visual Studio .NET
design-time support, including the
Properties window and Design view
previews.
Also, the only way to share
the user control between applications
is to put a separate copy in each
application, which takes more
maintenance if you make changes to the
control.
Web custom controls are compiled code,
which makes them easier to use but
more difficult to create; Web custom
controls must be authored in code.
Once you have created the control,
however, you can add it to the Toolbox
and display it in a visual designer
with full Properties window support
and all the other design-time features
of ASP.NET server controls.
In addition, you can install a single
copy of the Web custom control in the
global assembly cache and share it
between applications, which makes
maintenance easier. For more
information see global assembly cache.
Follow the following steps (from this post by Phil Haacked):
Close VS.NET 2005.
Open the directory C**:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp** (assuming a default installation of VS.NET).
Open the CSharpItems.vsdir file in Notepad. Select the text and copy it to the clipboard.
Now open up the file C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems\CSharpItems.vsdir and paste the contents of the clipboard underneath the existing text.
Now copy the contents of C:\Program Files\Microsoft Visual Studio 8\Web\WebNewFileItems\CSharp (excluding CSharpItems.vsdir) into the folder C:\Program Files\Microsoft Visual Studio 8\VC#\CSharpProjectItems.
Now “Web User Control” should be an option when you select Add | New Item.
Reference: http://haacked.com/archive/2006/02/07/addingwebusercontroltoaclasslibraryinvs.net2005.aspx
As platte's link mentions, if you're going for reuse then Web User Controls aren't very good. The ascx file has to be manually copied to every project you want to use them in, or you have to hack your way around that.
It's better to use System.Web.UI.WebControls.WebControl which is what you get when you add an "ASP.NET Server Control". These are designed for reuse. If one of the existing framework controls fits the bill for the most part and you just need to extend the functionality of it, then add an "ASP.NET Server Control" and change it to inherit from Panel or Menu or whatever.
If you're still determined to get reusable Web User Controls to work, then this article by The Gu should set you on the right path.
There is a project template called "ASP.NET Server Control" that I assume you can use...
--larsw
You can do anything in a class library.
Add reference to System.Web
Create your new Control class that inherits
from WebControl or HtmlControl or
whatever.
That's it. You now have a reusable control for ASP.NET.
You could do some special things like add attributes to your class and properties, but they are really not needed.
[DefaultProperty("Text")]
[Category("...")]
[DefaultValue("")]
You could using virtual path providers but you you should consider whether it really is worth your wile. Consider this codeproject article on the subject.

Resources