如何在浏览器中打开文件而不是下载文件 [英] How to open the files in browser rather than downloading the files

查看:221
本文介绍了如何在浏览器中打开文件而不是下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我需要一个小编码部分。我正在使用filegridview来显示gridview中的所有文件和文件夹。令人怀疑的是,它列出了所有文件,当我点击文件名时,它正在下载。如何在浏览器中打开这些文件而不是下载....这是我正在使用的功能....



Hi all

I need a small coding part to be done. I am using filegridview to display all files and folders in gridview. The doubt is, it lists all the files and when I click the name of the files, it is downloading. How to open those files in browser itself rather than downloading.... this is the function which I am using....

protected void gvFiles_RowDataBound(object sender, GridViewRowEventArgs e)
   {
       if (e.Row.RowType == DataControlRowType.DataRow)
       {
           var item = e.Row.DataItem as FileSystemItemCS;

           if (item.IsFolder)
           {
               var lbFolderItem = e.Row.FindControl("lbFolderItem") as LinkButton;
               lbFolderItem.Text = string.Format(@"<img src=""{0}"" alt="""" />&nbsp;{1}", Page.ResolveClientUrl("~/Images/folder.png"), item.Name);
           }
           else
           {
               var ltlFileItem = e.Row.FindControl("ltlFileItem") as Literal;
               if (this.CurrentFolder.StartsWith("~"))
                   ltlFileItem.Text = string.Format(@"<a href=""{0}"" target=""_blank"">{1}</a>",
                           Page.ResolveClientUrl(string.Concat(this.CurrentFolder, "/", item.Name).Replace("//", "/")),
                           item.Name);
               else
                   ltlFileItem.Text = item.Name;
           }
       }
   }





提前感谢....



thanks in advance....

推荐答案

这篇关于如何在浏览器中打开文件而不是下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆