【问题标题】:Images not displaying in adrotator where its picture path like "C:\Uploader\Image.jpg"图像未显示在 adrotator 中,其图片路径如“C:\Uploader\Image.jpg”
【发布时间】:2011-12-26 15:39:25
【问题描述】:

图像未显示在 adrotator 中,其图片路径如“C:\Uploader\Image.jpg”或服务器中的某个共享文件夹。如果我在项目内部提供路径,它可以工作但在项目外部(如“C: \Uploader\Image.jpg") 它没有显示任何内容。

<telerik:RadRotator ID="radSlider" runat="server" FrameDuration="400" ScrollDuration="500"
ScrollDirection="Left" Height="250px" Width="550px">
<ItemTemplate>
    <img src='<%# Eval("FullName") %>' alt="Friday" width="550px" />
 </ItemTemplate>
</telerik:RadRotator>

我在这里使用数据绑定动态附加路径。有什么问题。请帮助我?Telerik 或 asp 控件

【问题讨论】:

    标签: asp.net telerik


    【解决方案1】:

    除非您将虚拟目录映射到图像,否则客户端浏览器永远不会知道这些图像在哪里。即使您不能使用Server.MapPath() 等来映射驱动器。

    您应该使用HttpHandler 来访问您以外的文件 应用程序虚拟目录。

    检查以下与您的问题密切相关的 SO 线程:
    Show Images from outside of ASP.NET Application

    我在 goggle 之后得到的另一种方法如下:

    您可以尝试访问应用程序虚拟目录之外的文件。你需要注意文件夹/文件足够的权限。

    您可以访问您网站中的图片,您可以查看以下链接:

    Displaying images that are stored outside the Website Root Folder

    protected void Page_Load(object sender, EventArgs e)
    
    {
    
    if (Request.QueryString["FileName"] != null)
    
    {
    
        try
    
        {
    
            // Read the file and convert it to Byte Array
    
            string filePath = "C:\\images\\";
    
            string filename = Request.QueryString["FileName"];
    
            string contenttype = "image/" +
    
            Path.GetExtension(Request.QueryString["FileName"].Replace(".","");
    
            FileStream fs = new FileStream(filePath + filename,
    
            FileMode.Open, FileAccess.Read);
    
            BinaryReader br = new BinaryReader(fs);
    
            Byte[] bytes = br.ReadBytes((Int32)fs.Length);
    
            br.Close();
    
            fs.Close();
    
    
    
            //Write the file to response Stream
    
            Response.Buffer = true;
    
            Response.Charset = "";
    
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
    
            Response.ContentType = contenttype;
    
            Response.AddHeader("content-disposition", "attachment;filename=" + filename);
    
            Response.BinaryWrite(bytes);
    
            Response.Flush();
    
            Response.End();
    
        }
    
        catch
    
        {
    
        }
    
    }
    
    }
    

    希望对您有所帮助。

    【讨论】:

      【解决方案2】:

      您应该使用 IHttpHandler 在不同的位置(例如,在应用程序根目录之外或在特权文件夹中)提供您的文件。 AFAIK,Telerik Rad Controls 有一个 RadBinaryImage 或类似用途的东西。

      【讨论】:

        猜你喜欢
        • 2011-02-09
        • 1970-01-01
        • 2011-05-20
        • 1970-01-01
        • 1970-01-01
        • 2013-11-24
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多