Figure 1 Partially Trusted Code // Source for FileToConsole.exe
using System;
using System.IO;
using System.Security;
class App{
public static void Main(String[] args){
try{
StreamReader sr = new StreamReader(args[0]);
Console.WriteLine(sr.ReadToEnd());
}catch(SecurityException){
Console.WriteLine("FileToConsole does not have sufficient"
"security privileges to access the file!");
}catch(Exception){Usage()};
}
static private void Usage(){
Console.WriteLine("Usage: FileToConsole [FileName]");
}
}
Figure 4 Zones
Zone |
Description |
Internet |
Assemblies from the Internet zone have highly restricted access to the file system, registry, and other system resources. |
Intranet |
Assemblies from the intranet zone are restricted from accessing the local file system and registry. |
MyComputer |
Assemblies from the MyComputer or local zone are given full trust. |
Trusted |
Some Web sites can be configured to be more trusted than the typical Internet site. |
Untrusted |
Web sites configured as Untrusted cannot be used to execute managed controls. | Figure 5 Controls.cs using System;
using System.Windows.Forms;
// Derive a class from ListBox
// ListBox is derived from Control
public class DragListBox:ListBox{
public DragListBox(){
// Add support for drag and drop
AllowDrop = true;
}
// Public method for adding items to the control
public void AddItem(String item){
Items.Add(item);
}
// Implement Drag and Drop addition to ListBox
protected override void OnDragEnter(DragEventArgs drgevent){
if(drgevent.Data.GetDataPresent(typeof(DragItem))){
drgevent.Effect = DragDropEffects.Move;
}
}
protected override void OnDragDrop( DragEventArgs drgevent){
DragItem item =
(DragItem) drgevent.Data.GetData(typeof(DragItem));
Items.Add(item.item);
}
protected override void OnMouseMove(MouseEventArgs e){
Int32 index = SelectedIndex;
if(index != -1 && ((e.Button & MouseButtons.Left) != 0)){
DragItem item = new DragItem();
item.item = Items[index];
item.sender = this;
DragDropEffects result =
DoDragDrop(item, DragDropEffects.Move);
if( result == DragDropEffects.Move){
Items.RemoveAt(index);
}
}
base.OnMouseMove(e);
}
// Private class for dragged data
class DragItem{
public Object item;
public DragListBox sender;
}
}
Figure 6 Controls.html <html>
<head>
<title>Interacting Controls Example</title>
</head>
<body onload="NavigateTo()" bgColor="gainsboro">
<h1>
Interacting Controls
</h1>
<hr>
<OBJECT id="List1" classid="http:Controls.dll#DragListBox">
</OBJECT>
</hr>
<br>
You can drag items from one list box to the other.
<hr>
<OBJECT id="List2" classid="http:Controls.dll#DragListBox">
</OBJECT>
</hr>
<SCRIPT LANGUAGE="JScript">
// Code to add items to one of the lists
function NavigateTo(){
List1.AddItem("Inky");
List1.AddItem("Pinky");
List1.AddItem("Blinky");
List1.AddItem("Clyde");
}
</SCRIPT>
</body>
</html>
|