目由门,无界等最新版的,如方便请发skynetdo@qvodart gmail.comm,...

.com.cn
.net.cn
.gov.cn
.org.cn
.com.tw
验证:
本站可以查询世界大部分域名WHOIS,并且支持批量查询,如果没有你所要查询的域名后缀选择,建议你使用批量查询。
最新查询的域名:
热门查询的域名:
域名查询目录:
首页连接整理提示:首页只接受PR5以上的交换连接,谢谢你的理解和支持!
酷站推荐:
© 2009Advanced ASP.NET upload component
ASP.NET File Upload like GMail
Ajax Uploader is an easy to use, hi-performance ASP.NET File Upload Control which allows you to upload files to web server without refreshing the page.
It allows you select and upload multiple files and cancel ru ing file uploads, add new files during uploading.
Ajax Uploader uploads large files to a server with low server memory co umption. The look and feel of file upload control can be customized to seamle ly blend into your we ite design.
Top features
Select multiple files at once when sending Ajax Uploader allows you to select and upload multiple files at once rather than having to select and upload each file individually.
Client side validation of the file size/type before uploading Client side validation of file size/types prior to uploading the files to a server to increase usability and reduce co umption of network and server resources.
Hi-Performance with optimized memory usage
By streaming uploads directly to an output stream, rather than loading them into memory, Ajax Uploader achieves a level of scalability and performance impo ible to reach with ASP.NET's built-in functionality.
Provides rich progre and status information during the upload
Ajax Uploader has a real time progre bar which kee track of every file upload. It offers an accurate and detailed progre indicator to end-users. It also gives end-users the ability to cancel uploads in progre .
Powerful a roaches to uploading files without refreshing the page
Ever wanted to upload files using AJAX like in GMAIL, without reloading the page?
This Ajax version File Upload Control can also be placed in an UpdatePanel.
Asynchronous file upload
This mea that the file is uploaded in the background, allowing user to still use the page while the file is being uploaded.
Compatible with IE 5.5+, Firefox 1.0+, Mozilla 1.3+, Netscape 7+, Opera 9.x, Google Chrome and Safari (1.3+). This includes Macintosh and Linux.
Compatible with .NET Framework 1.1, 2.0, 3.0, 3.5, 4.0 and MVC.
This control is also available for8,002,870 members and growing! (41,362 online)
Pa word
Remember me? Quick A wers
Programming Discu io Other Languages
Search within:
Articles
Quick A wers
Me ages
Product Catalog
Licence First Posted 30 Jan 2007
View 293,728
Download 50,695
Bookmarked 240 times
.NET Interop for Gadgets – A C# GMail I ox Reader Example
30 Jan 2007
How to call a olutely any .NET code from your Vista Sidebar Gadget
Prize wi er in Competition
"All Topics Mar 2007"
Prize wi er in Competition
"All Topics Jan 2007" See Also
Add to your CodeProject bookmarks
Article 4.79
103 votes
4.79/5 - 103 votes
18 removed
μ 4.38, σ
Spo ored Links
Contents
Introduction
Since the writing of
, I've been wrestling with the frustration of not being able to do with a gadget what can be easily done with .NET. I love how compact and simple gadgets can be, but I find it hard to build a truly useful gadget simply because there's no real power using JavaScript. Unfortunately for the .NET community, gadgets rely almost purely on JavaScript. It's hard to mix my excitement for gadgets with their huge limitatio .
If only I could run .NET code from gadgets
Enter Gadget .NET Interop!
In this article we'll explore how to build an interop layer between gadgets and .NET so you can run any .NET code from your sidebar gadget. We'll do that by building a C# project to read your GMail i ox.
COM and ActiveX
It's not fair to say that gadget's can't run .NET code. The truth is that it's very easy to create COM object i tances from scripting languages. The real problem is that it's terribly inconvenient to have to register all your code for COM interop. Doing so would require you to first modify all your code to be COM compatible. Then you'd have to re-package your code and distribute an MSI file along with each and every gadget just to i tall and register your a embly (and po ibly add it to the GAC if it's going to be shared acro gadgets). That kind of workaround i 't a realistic solution, e ecially if you already have code that you don't want to rewrite and package just for COM interop. Further, you can't a ume your users have the knowledge or
a COM component.
What's the a wer then?
No matter what, there must be some COM pieces in place; otherwise we'll never get past the limitatio of JavaScript. We'll get to the GMail part once we have a suitable COM layer (see below if you're comfortable with COM in .NET). Let's start with the real nuts and bolts of the solution by creating a basic COM object that can be used load any .NET a embly.
.NET COM Interface
The idea is simple; create a small, lightweight .NET COM component that uses reflection to load any a embly and type. Then, that type can be called directly from JavaScript. Let's take a look at the interface for the "Gadget Adapter" that will do the bulk of the work.
[ComVisible(
GuidAttribute(
618ACBAF-B4BC-4165-8689-A0B7D7115B05
InterfaceType(ComInterfaceType.InterfaceIsDual)]
interface
IGadgetInterop
LoadType(
a emblyFullPath,
cla Name);
LoadTypeWithParams(
a emblyFullPath,
cla Name,
preserveParams);
AddCo tructorParam(
parameter);
UnloadType(
typeToUnload);
There are only four methods that the implementing Gadget Adapter cla will need to handle. The point to take note of is that the interface has three attributes that will allow us to expose the implementing cla as a COM object. Four methods are all we need to create and call any type in managed code.
Gadget Adapter
Now that the interface is defined, let's look at the actual Gadget Adapter implementation of this interface. We'll break it out piece-by-piece starting with the cla attributes.
[ComVisible(
GuidAttribute(
89BB4535-5AE9-43a0-89C5-19B4697E5C5E
ProgId(
GadgetInterop.GadgetAdapter
Cla Interface(Cla InterfaceType.None)]
cla GadgetAdapter : IGadgetInterop
There are a few differences between these attributes and the attributes on the interface. The most important attribute for our purposes is the "ProgId" attribute. This attribute represents the string we'll use to create the ActiveX object via JavaScript. Now that the
GadgetAdapter
is decorated properly, the next step is loading a emblies and creating cla i tances. The
AddCo tructorParam
method allows JavaScript code to add values that will be pa ed to the cla co tructor's arguments. This is only nece ary when want to load a .NET type using a co tructor with one or more arguments.
private
ArrayList paramList =
ArrayList();
AddCo tructorParam(
parameter)
paramList.Add(parameter);
The next method is where all the magic ha e . The
LoadTypeWithParams
method has the three arguments that allow any .NET a embly to be loaded. The method takes the path to the a embly, the type to create, and a flat for handling co tructor parameter di osal.
LoadTypeWithParams(
a emblyFullPath,
cla Name,
preserveParams)
A embly a embly = A embly.LoadFile(a emblyFullPath);
[] arguments =
(paramList !=
&am am paramList.Count
arguments =
[paramList.Count];
paramList.CopyTo(arguments);
BindingFlags bindings = BindingFlags.CreateI tance |
BindingFlags.I tance |
BindingFlags.Public;
loadedType = a embly.CreateI tance(cla Name,
, bindings,
, arguments, CultureInfo.InvariantCulture,
loadedType;
Using standard .NET reflection, the ecified a embly is loaded and an i tance of the i ut type is created. That i tance is returned and is then directly callable by JavaScript (more on that to come). The
preserveParams
flag prevents the co tructor arguments from being cleared after the object is created. This is only nece ary when you're creating multiple i tances of a cla with the same co tructor arguments.
Finally, because we're in the COM world, we have to be careful to do our own object di osal. The
UnloadType
method calls di ose of the incoming object to allow for graceful cleanup.
UnloadType(
typeToUnload)
(typeToUnload !=
&am am typeToUnload
IDi osable)
(typeToUnload
IDi osable).Di ose();
typeToUnload =
The one convention I opted for is that cla es exposed to gadgets must implement
IDi osable
, so only types implementing that interface will work with the sample code. That's all there is to the interop layer. It creates .NET objects and it destroys .NET object nothing more, nothing le .
Automatic Registration at Runtime
Now we have a working COM-friendly Gadget Adapter, but how does it get registered? Normally you would rely on an MSI i taller to register and GAC your COM components. Remember that the goal here is to run .NET code in a gadget without the user having to i tall an MSI. To get around the MIS (or
RegAsm.exe
) we can "fake" the registration by adding the right values directly to the registry (My thanks to Frederic Queudret for this idea). The
GadgetInterop.js
a JavaScript library is designed to facilitate the Gadget Adapter registration (as well as all the COM object wra ing). The
RegAsmI tall
JavaScript method takes all the information about the Gadget Adapter interop a embly and creates all the nece ary registry entries to register it. The beauty of this step is that any gadget can register the interop layer at runtime the first time the gadget executes.
function
RegAsmI tall(root, progId, cls, clsid, a embly, version, codebase)
wshShell;
wshShell =
ActiveXObject(
WScript.Shell
wshShell.RegWrite(root +
\\Software\\Cla es\\, progId);
wshShell.RegWrite(root +
\\Software\\Cla es\\
+ progId +
, cls);
wshShell.RegWrite(root +
\\Software\\Cla es\\
+ progId + \\CLSID\\,
clsid);
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\ + clsid +
, cls);
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\
mscoree.dll
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\ThreadingModel
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\Cla
, cls);
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\A embly
, a embly);
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\RuntimeVersion
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\CodeBase
, codebase);
wshShell.RegWrite(root +
\\Software\\Cla es\\CLSID\\
+ clsid +
\\I rocServer32\\
+ version +
, cls);
wshShell.RegWr

参考资料

 

随机推荐