使我的幻灯片仅使用.jpg文件。 [英] Make my slideshow use .jpg files only.

查看:79
本文介绍了使我的幻灯片仅使用.jpg文件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个成功的幻灯片显示问题。每次更新images文件夹中的jpeg文件时,Windows都会将thumbs.db文件放在images文件夹中。我试图阻止thumbs.db文件但没有成功。有人可以告诉我如何阻止它们或让我的幻灯片只播放.jpg文件。

这是我的幻灯片代码。

  Imports  System.IO 
Imports AjaxControlToolkit
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Collections.Generic

Partial Class 早餐
继承 System.Web.UI.Page

< WebMethod()> _
< ScriptMethod()> _
公开 共享 功能 GetImages() As Slide()
Dim slide 作为 列表( 幻灯片)()
Dim sPath As String = HttpContext.Current.Server.MapPath ( 〜/ ImagesLunch /
如果 sPath.EndsWith( \然后
sPath = sPath.Remove(sPath.Length - 1
结束 如果
Dim pathUri 作为 Uri(sPath, UriKind.Absolute)
Dim 个文件 As String ()= Directory.GetFiles(sPath)
对于 每个文件作为 字符串 个文件中
Dim filePathUri 作为 Uri(文件,UriKind。绝对)
slides.Add( Slide()使用 {_
。 Name = Path.GetFileNameWithoutExtension(file),_
.Description = Path.GetFileNameWithoutExtension(file)+ Description。,_
.ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString()_
})
下一步
返回 slides.ToArray()
结束 功能





我尝试过:



我尝试使用GP停止缓存缩略图,但这没有效果。

解决方案

< blockquote>如果要包含的所有文件具有相同的扩展名,请将搜索模式传递​​给 GetFiles 方法:

  Dim 文件作为 字符串()= Directory.GetFiles(sPath,  *。jpg



否则,排除隐藏文件和扩展名不受支持的文件:

 对于 每个 file 文件中 字符串  
Dim attr As FileAttributes = File.GetAttributes(file)
如果 attr.HasFlag(FileAttributes.Hidden) OrElse attr.HasFlag(FileAttributes.System)然后
' 跳过文件
继续 对于
结束 如果

Dim extension As 字符串 = Path.GetExtension(文件)
如果 SupportedExtensions .Contains(扩展名)然后
' 跳过文件
继续 对于
结束 如果

' 添加幻灯片
...
下一步

.. 。

私人 共享 ReadOnly SupportedExtensions 作为 HashSet( 字符串)(StringComparer.OrdinalIgn oreCase)来自{
。jpg
。jpe
。jpeg
。png
。gif
}


I have a successful slideshow that I am using which developed a problem. Windows places a thumbs.db file in the images folder every time I update the jpeg files in the images folder. I have tried to block the thumbs.db files without success. Can someone tell me how to block them or make my slideshow only pickup .jpg files.
Here is my slideshow code.

Imports System.IO
Imports AjaxControlToolkit
Imports System.Web.Services
Imports System.Web.Script.Services
Imports System.Collections.Generic
 
Partial Class Breakfast
    Inherits System.Web.UI.Page
 
    <WebMethod()> _
        <ScriptMethod()> _
    Public Shared Function GetImages() As Slide()
        Dim slides As New List(Of Slide)()
        Dim sPath As String = HttpContext.Current.Server.MapPath("~/ImagesLunch/")
        If sPath.EndsWith("\") Then
            sPath = sPath.Remove(sPath.Length - 1)
        End If
        Dim pathUri As New Uri(sPath, UriKind.Absolute)
        Dim files As String() = Directory.GetFiles(sPath)
        For Each file As String In files
            Dim filePathUri As New Uri(file, UriKind.Absolute)
            slides.Add(New Slide() With { _
              .Name = Path.GetFileNameWithoutExtension(file), _
              .Description = Path.GetFileNameWithoutExtension(file) + " Description.", _
              .ImagePath = pathUri.MakeRelativeUri(filePathUri).ToString() _
            })
        Next
        Return slides.ToArray()
    End Function



What I have tried:

I tried using GP to stop caching thumbnails but that has had no effect.

解决方案

If all the files you want to include have the same extension, pass the search pattern to the GetFiles method:

Dim files As String() = Directory.GetFiles(sPath, "*.jpg")


Otherwise, exclude hidden files and files with unsupported extensions:

For Each file As String in files
    Dim attr As FileAttributes = File.GetAttributes(file)
    If attr.HasFlag(FileAttributes.Hidden) OrElse attr.HasFlag(FileAttributes.System) Then
        ' Skip the file
        Continue For
    End If
    
    Dim extension As String = Path.GetExtension(file)
    If Not SupportedExtensions.Contains(extension) Then
        ' Skip the file
        Continue For
    End If
    
    ' Add the slide
    ...
Next

...

Private Shared ReadOnly SupportedExtensions As New HashSet(Of String)(StringComparer.OrdinalIgnoreCase) From { 
    ".jpg",
    ".jpe",
    ".jpeg",
    ".png",
    ".gif"
}


这篇关于使我的幻灯片仅使用.jpg文件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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