コード例 #1
0
ファイル: SiteFile.aspx.cs プロジェクト: zhongshuiyuan/MT2017
        /// <summary>
        /// 图标视图控件生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                FileSystemInfo file     = e.Item.DataItem as FileSystemInfo;
                String         filepath = "/" + RootPath.MakeRelativeUri(new Uri(file.FullName)).ToString();

                HyperLink   link = (HyperLink)e.Item.FindControl("Link");
                ImageButton del  = (ImageButton)e.Item.FindControl("del");
                ImageButton edit = (ImageButton)e.Item.FindControl("edit");
                ImageButton save = (ImageButton)e.Item.FindControl("save");
                ImageButton cut  = (ImageButton)e.Item.FindControl("cut");

                del.OnClientClick  = String.Format("javascript:dialogConfirm({{el:this,text:'将删除 {0} 且无法恢复!确定要删除吗?'}});return false;", file.Name);
                edit.OnClientClick = String.Format("javascript:dialogIFrame({{ url: 'SiteFile.aspx?action=rename&file={1}', title: '重命名 - {0}', width: 350, height: 250 }});return false;", file.Name, Server.UrlEncode(filepath));

                Image ico = new Image();
                ico.ImageUrl = "../skin/transparent.gif";
                ico.Style.Add("background-position", "center center");

                link.Controls.Add(ico);

                if (file.Attributes == FileAttributes.Directory)
                {
                    link.NavigateUrl = "SiteFile.aspx?dir=" + filepath;
                    ico.Style.Add("background-image", "../skin/files/folder_large.png");
                }
                else
                {
                    save.Visible = true;

                    FileInfo _file = file as FileInfo;
                    String   ex    = String.IsNullOrEmpty(_file.Extension) ? "none" : _file.Extension.Substring(1).ToLower();

                    String src = String.Format("../skin/files/{0}_large.png", ex);
                    if (!icons.Contains(ex))
                    {
                        src = "../skin/files/none_large.png";
                    }
                    ico.Style.Add("background-image", src);

                    switch (ex)
                    {
                    case "gif":
                    case "jpeg":
                    case "png":
                    case "bmp":
                    case "jpg":
                        cut.Visible       = true;
                        cut.OnClientClick = String.Format("javascript:dialogIFrame({{ url: '../Plugin-S/Kroppr/Kroppr.aspx?file={1}', title: '剪切 - {0}', width: 700, height: 480 }});return false;", file.Name, Server.UrlEncode(filepath));

                        link.NavigateUrl = filepath;
                        link.Attributes.Add("rel", "group1");
                        link.Attributes.Add("class", "lightbox");
                        ico.Style["background-image"] = "../Plugin-S/Thumbnail.aspx?w=110&h=146&file=" + filepath;
                        break;

                    case "aspx":
                    case "asax":
                    case "ascx":
                    case "cs":
                    case "ashx":
                    case "config":
                    case "js":
                    case "css":
                    case "txt":
                    case "htm":
                    case "html":
                    case "xml":
                    case "asp":
                    case "shtml":
                    case "ini":
                    case "as":
                    case "md":
                    case "json":
                    case "yml":
                        link.NavigateUrl = "javascript:";
                        link.Attributes.Add("onclick", String.Format("javascript:dialogIFrame({{ url: 'SiteFile.aspx?action=edit&file={1}', title: '编辑 - {0}', width: 700, height: 500}});return false;", file.Name, Server.UrlEncode(filepath)));
                        break;
                    }
                }
            }
        }
コード例 #2
0
ファイル: SiteFile.aspx.cs プロジェクト: zhongshuiyuan/MT2017
        /// <summary>
        /// 列表视图控件生成
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                FileSystemInfo file     = e.Item.DataItem as FileSystemInfo;
                String         filepath = "/" + RootPath.MakeRelativeUri(new Uri(file.FullName)).ToString();

                HtmlTableRow row  = (HtmlTableRow)e.Item.FindControl("row");
                ImageButton  del  = (ImageButton)e.Item.FindControl("del");
                ImageButton  edit = (ImageButton)e.Item.FindControl("edit");
                ImageButton  save = (ImageButton)e.Item.FindControl("save");
                del.OnClientClick  = String.Format("javascript:dialogConfirm({{el:this,text:'将删除 {0} 且无法恢复!确定要删除吗?'}});return false;", file.Name);
                edit.OnClientClick = String.Format("javascript:dialogIFrame({{ url: 'SiteFile.aspx?action=rename&file={1}', title: '重命名 - {0}', width: 350, height: 250 }});return false;", file.Name, Server.UrlEncode(filepath));

                HtmlTableCell td1 = (HtmlTableCell)row.Controls[1];
                Image         ico = new Image();
                ico.Attributes.Add("align", "absmiddle");
                ico.Attributes.Add("style", "padding-right:5px;");
                td1.Controls.Add(ico);

                HyperLink link = new HyperLink();
                link.Text    = file.Name;
                link.ToolTip = file.Name;
                td1.Controls.Add(link);

                if (file.Attributes == FileAttributes.Directory)
                {
                    link.NavigateUrl = "SiteFile.aspx?dir=" + filepath;
                    ico.ImageUrl     = "../skin/files/folder_small.png";
                }
                else
                {
                    save.Visible = true;
                    FileInfo _file = file as FileInfo;
                    String   ex    = String.IsNullOrEmpty(_file.Extension) ? "none" : _file.Extension.Trim('.');

                    HtmlTableCell td4  = row.Controls[4] as HtmlTableCell;
                    long          size = _file.Length;
                    td4.InnerText = FileHelper.FileSizeToStr((long)(size));

                    String src = String.Format("../skin/files/{0}_small.png", ex);
                    if (!icons.Contains(ex))
                    {
                        src = "../skin/files/none.png";
                    }
                    ico.ImageUrl = src;

                    switch (ex)
                    {
                    case "gif":
                    case "jpeg":
                    case "png":
                    case "bmp":
                    case "jpg":
                        link.NavigateUrl = filepath;
                        link.Attributes.Add("rel", "group1");
                        link.Attributes.Add("class", "lightbox");
                        Image exlink = new Image();
                        exlink.ImageAlign = ImageAlign.Baseline;
                        exlink.ToolTip    = "查看大图";
                        exlink.Style.Add("margin-left", "5px");
                        exlink.Attributes.Add("align", "absmiddle");
                        exlink.ImageUrl = "../skin/icos/Link.png";
                        td1.Controls.Add(exlink);
                        break;

                    case "aspx":
                    case "asax":
                    case "ascx":
                    case "cs":
                    case "ashx":
                    case "config":
                    case "js":
                    case "css":
                    case "txt":
                    case "htm":
                    case "html":
                    case "xml":
                    case "asp":
                    case "shtml":
                    case "ini":
                    case "as":
                    case "md":
                    case "json":
                    case "yml":
                        link.NavigateUrl = "javascript:";
                        link.Attributes.Add("onclick", String.Format("javascript:dialogIFrame({{ url: 'SiteFile.aspx?action=edit&file={1}', title: '编辑 - {0}', width: 700, height: 500}});return false;", file.Name, Server.UrlEncode(filepath)));
                        break;

                    case "rar":
                    case "pdf":
                    case "ppt":
                    case "pptx":
                    case "doc":
                    case "docx":
                    case "mdb":
                    case "accdb":
                    case "xlsx":
                    case "xls":
                    case "psd":
                    case "wma":
                    case "chm":

                        break;
                    }
                }
            }
        }