我按照此链接Ajax Slide show extender
的说明进行操作我的代码如下
<div>
<table style="border:Solid 3px #D55500; width:400px; height:400px" cellpadding="0"
cellspacing="0">
<tr style="background-color:#D55500">
<td style=" height:10%; color:White; font-weight:bold; font-size:larger"
align="center">
<asp:Label ID="lblTitle" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:Image ID="imgslides" runat="server" Height="400px" Width="400px" />
</td>
</tr>
<tr>
<td align="center">
<asp:Label ID="lblimgdesc" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="center">
<asp:Button ID="btnPrevious" runat="server" Text="Prev" CssClass="button" />
<asp:Button ID="btnPlay" runat="server" Text="Play" CssClass="button" />
<asp:Button ID="btnNext" runat="server" Text="Next" CssClass="button" />
</td>
</tr>
</table>
<ajax:SlideShowExtender runat="server" AutoPlay="true" ImageTitleLabelID="lblTitle"
ImageDescriptionLabelID="lblimgdesc" Loop="true"
NextButtonID="btnNext" PreviousButtonID="btnPrevious" PlayButtonID="btnPlay"
PlayButtonText="Play" StopButtonText="Stop"
TargetControlID="imgslides" SlideShowServicePath="Slideshow.asmx"
SlideShowServiceMethod="GetSlides"></ajax:SlideShowExtender>
在我的网络服务中我有一个文件
[WebMethod]
public AjaxControlToolkit.Slide[] GetSlides()
{
string[] ImageNames = System.IO.Directory.GetFiles(Server.MapPath(@"C:\Users\Mayer\Documents\Visual Studio 2010\Projects\Project1\Project1\Images\"));
AjaxControlToolkit.Slide[] photos = new AjaxControlToolkit.Slide[ImageNames.Length];
for (int i = 0; i < ImageNames.Length; i++)
{
string[] file = ImageNames[i].Split('\\');
photos[i] = new AjaxControlToolkit.Slide("Images/" + file[file.Length - 1], file[file.Length - 1], "");
}
return photos;
}
我有图片文件夹,但我看不到我的幻灯片
请帮忙
答案 0 :(得分:3)
您应该将相对地址传递给Server.MapPath
应该是:~\Project1\Project1\Images\
而不是物理路径:
C:\Users\Mayer\Documents\Visual Studio 2010\Projects\Project1\Project1\Images\
MapPath方法将指定的相对或虚拟路径映射到 服务器上对应的物理目录。
来自文档: http://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx