PageRenderTime 103ms CodeModel.GetById 97ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 1ms

/Demo/Customized.aspx

http://izwebfilemanager.googlecode.com/
ASP.NET | 172 lines | 153 code | 19 blank | 0 comment | 5 complexity | 546d1a96e65349ab99342e80106bf13e MD5 | raw file
  1<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPage.master" %>
  2
  3<%@ Register Assembly="IZ.WebFileManager" Namespace="IZ.WebFileManager" TagPrefix="iz" %>
  4
  5<script runat="server">
  6
  7	protected void FileManager1_ExecuteCommand (object sender, ExecuteCommandEventArgs e) {
  8		e.ClientScript = "alert('Use ExecuteCommand event to handle your custom command.\\nCommandName=" + e.CommandName + "\\nItem=" + e.Items [0].AbsolutePath + "')";
  9	}
 10
 11	protected void CheckBox1_CheckedChanged (object sender, EventArgs e) {
 12		FileManager1.ReadOnly = ((CheckBox) sender).Checked;
 13	}
 14
 15	protected void CheckBox2_CheckedChanged (object sender, EventArgs e) {
 16		FileManager1.AllowUpload = ((CheckBox) sender).Checked;
 17	}
 18
 19	protected void CheckBox3_CheckedChanged (object sender, EventArgs e) {
 20		FileManager1.AllowDelete = ((CheckBox) sender).Checked;
 21	}
 22
 23	protected void CheckBox4_CheckedChanged (object sender, EventArgs e) {
 24		FileManager1.AllowOverwrite = ((CheckBox) sender).Checked;
 25	}
 26
 27	protected void CheckBox5_CheckedChanged (object sender, EventArgs e) {
 28		FileManager1.UseLinkToOpenItem = ((CheckBox) sender).Checked;
 29	}
 30
 31	protected void CheckBox6_CheckedChanged (object sender, EventArgs e) {
 32		FileManager1.ShowHiddenFilesAndFolders = ((CheckBox) sender).Checked;
 33	}
 34
 35	protected void CheckBox7_CheckedChanged (object sender, EventArgs e) {
 36		FileManager1.DownloadOnDoubleClick = ((CheckBox) sender).Checked;
 37	}
 38
 39	protected void FileManager1_ToolbarCommand (object sender, CommandEventArgs e) {
 40		if (e.CommandName == "CreateZip") {
 41
 42			string zipFile = System.IO.Path.Combine (FileManager1.CurrentDirectory.PhysicalPath, "ZIP_" + DateTime.Now.ToString ("yyyyMMddHHmmss") + ".zip");
 43
 44			//Create an empty zip file
 45			byte [] emptyzip = new byte [] { 80, 75, 5, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
 46
 47			using (System.IO.FileStream fs = System.IO.File.Create (zipFile)) {
 48				fs.Write (emptyzip, 0, emptyzip.Length);
 49				fs.Flush ();
 50				fs.Close ();
 51			}
 52
 53			string [] selectedItems = new string [FileManager1.SelectedItems.Length];
 54			for (int i = 0; i < FileManager1.SelectedItems.Length; i++) {
 55				selectedItems [i] = System.IO.Path.GetFileName (FileManager1.SelectedItems [i].PhysicalPath);
 56			}
 57			//Copy a folder and its contents into the newly created zip file
 58			Shell32.ShellClass sc = new Shell32.ShellClass ();
 59			Shell32.Folder DestFlder = sc.NameSpace (zipFile);
 60			Shell32.Folder SrcFlder = sc.NameSpace (FileManager1.CurrentDirectory.PhysicalPath);
 61			Shell32.FolderItems items = SrcFlder.Items ();
 62			foreach (Shell32.FolderItem item in items) {
 63				if (Array.LastIndexOf<string> (selectedItems, item.Name) >= 0)
 64					DestFlder.CopyHere (item, 20);
 65			}
 66
 67			//Ziping a file using the Windows Shell API creates another thread where the zipping is executed.
 68			//This means that it is possible that this console app would end before the zipping thread 
 69			//starts to execute which would cause the zip to never occur and you will end up with just
 70			//an empty zip file. So wait a second and give the zipping thread time to get started
 71			System.Threading.Thread.Sleep (1000);
 72		}
 73		else {
 74			throw new InvalidOperationException ();
 75		}
 76	}
 77</script>
 78
 79<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
 80
 81	<script type="text/javascript">
 82    function OpenItem(path) {
 83        alert('Use ClientOpenItemFunction property to handle Open command\npath='+path);
 84    }
 85	</script>
 86
 87	<div style="margin-top: 8px; margin-bottom: 8px;">
 88		Use your custom File Types, Commands & New Document Templates<br />
 89		<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox1_CheckedChanged"
 90			Text="ReadOnly" />&nbsp;&nbsp;<asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="True"
 91				Checked="True" OnCheckedChanged="CheckBox2_CheckedChanged" Text="AllowUpload" />&nbsp;<asp:CheckBox
 92					ID="CheckBox3" runat="server" AutoPostBack="True" Checked="True" OnCheckedChanged="CheckBox3_CheckedChanged"
 93					Text="AllowDelete" />
 94		<asp:CheckBox ID="CheckBox4" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox4_CheckedChanged"
 95			Text="AllowOverwrite" />
 96		<asp:CheckBox ID="CheckBox5" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox5_CheckedChanged"
 97			Text="UseLinkToOpenItem" />
 98		<asp:CheckBox ID="CheckBox6" runat="server" AutoPostBack="True" Checked="true" OnCheckedChanged="CheckBox6_CheckedChanged"
 99			Text="ShowHiddenFolders" />
100		<asp:CheckBox ID="CheckBox7" runat="server" AutoPostBack="True" OnCheckedChanged="CheckBox7_CheckedChanged"
101			Text="DownloadOnDoubleClick" /></div>
102	<div>
103		<iz:FileManager ID="FileManager1" runat="server" Height="400px" Width="600" OnExecuteCommand="FileManager1_ExecuteCommand"
104			ClientOpenItemFunction="OpenItem" OnToolbarCommand="FileManager1_ToolbarCommand"
105			HiddenFilesAndFoldersPrefix="_" ShowHiddenFilesAndFolders="true" HiddenFiles="config, ini">
106			<RootDirectories>
107				<iz:RootDirectory DirectoryPath="~/Files/My Documents" Text="My Documents" />
108			</RootDirectories>
109			<CustomToolbarButtons>
110				<iz:CustomToolbarButton Text="Create Zip" CommandName="CreateZip" ImageUrl="images/16x16/zip.gif" />
111				<iz:CustomToolbarButton Text="Say Hello!" PerformPostBack="false" OnClientClick="alert('Hello!')"
112					ImageUrl="images/16x16/smile.gif" />
113			</CustomToolbarButtons>
114			<ToolbarOptions ShowRefreshButton="false" />
115			<Templates>
116				<iz:NewDocumentTemplate Name="HTML Page" NewFileName="New HTML File" MasterFileUrl="Templates/HTMLPage.htm" />
117				<iz:NewDocumentTemplate Name="JScript File" NewFileName="JScript" MasterFileUrl="Templates/JScript.js" />
118				<iz:NewDocumentTemplate Name="Style Sheet" NewFileName="StyleSheet" MasterFileUrl="Templates/StyleSheet.css" />
119			</Templates>
120			<FileTypes>
121				<iz:FileType Extensions="zip, rar, iso" Name="Archive" SmallImageUrl="images/16x16/compressed.gif"
122					LargeImageUrl="images/32x32/compressed.gif">
123				</iz:FileType>
124				<iz:FileType Extensions="doc, rtf" Name="Microsoft Word Document" SmallImageUrl="images/16x16/word.gif"
125					LargeImageUrl="images/32x32/word.gif">
126				</iz:FileType>
127				<iz:FileType Extensions="xls, csv" Name="Microsoft Excel Worksheet" SmallImageUrl="images/16x16/excel.gif"
128					LargeImageUrl="images/32x32/excel.gif">
129				</iz:FileType>
130				<iz:FileType Extensions="ppt, pps" Name="Microsoft PowerPoint Presentation" SmallImageUrl="images/16x16/PowerPoint.gif"
131					LargeImageUrl="images/32x32/PowerPoint.gif">
132				</iz:FileType>
133				<iz:FileType Extensions="gif, jpg, png" Name="Image" SmallImageUrl="images/16x16/image.gif"
134					LargeImageUrl="images/32x32/image.gif">
135				</iz:FileType>
136				<iz:FileType SmallImageUrl="images/16x16/media.gif" Name="Windows Media File" Extensions="mp3,wma,vmv,avi,divx"
137					LargeImageUrl="images/32x32/media.gif">
138				</iz:FileType>
139				<iz:FileType Extensions="txt" Name="Text Document">
140					<Commands>
141						<iz:FileManagerCommand Name="Edit" CommandName="EditText" SmallImageUrl="images/16x16/edit.gif" />
142					</Commands>
143				</iz:FileType>
144				<iz:FileType Extensions="xml, xsl, xsd" Name="XML Document" LargeImageUrl="images/32x32/xml.gif"
145					SmallImageUrl="images/16x16/xml.gif">
146					<Commands>
147						<iz:FileManagerCommand Name="Edit" CommandName="EditText" SmallImageUrl="images/16x16/edit.gif" />
148					</Commands>
149				</iz:FileType>
150				<iz:FileType Extensions="css" Name="Cascading Style Sheet" LargeImageUrl="images/32x32/styleSheet.gif"
151					SmallImageUrl="images/16x16/styleSheet.gif">
152					<Commands>
153						<iz:FileManagerCommand Name="Edit" CommandName="EditText" SmallImageUrl="images/16x16/edit.gif" />
154					</Commands>
155				</iz:FileType>
156				<iz:FileType Extensions="js, vbs" Name="Script File" LargeImageUrl="images/32x32/script.gif"
157					SmallImageUrl="images/16x16/script.gif">
158					<Commands>
159						<iz:FileManagerCommand Name="Edit" CommandName="EditText" SmallImageUrl="images/16x16/edit.gif" />
160					</Commands>
161				</iz:FileType>
162				<iz:FileType Extensions="htm, html" Name="HTML Document" LargeImageUrl="images/32x32/html.gif"
163					SmallImageUrl="images/16x16/html.gif">
164					<Commands>
165						<iz:FileManagerCommand Name="Edit with WYSWYG editor" CommandName="WYSWYG" />
166						<iz:FileManagerCommand Name="Edit" CommandName="EditText" SmallImageUrl="images/16x16/edit.gif" />
167					</Commands>
168				</iz:FileType>
169			</FileTypes>
170		</iz:FileManager>
171	</div>
172</asp:Content>