我构建了这个应用程序,显示存储在多个sharepoint文件夹中的员工照片。它还显示从文件名中提取的员工姓名以及在照片中移动的上一个和下一个按钮。
标记被更新面板包围,以防止在您单击以查看下一张照片时重新加载整个页面。
该应用程序在Firefox中运行良好,但图像不显示在IE8中。任何人都能说出造成这种情况的原因吗?
public List<string> photoFileList = new List<string>();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["index"] = 0;
Session["CountOfPictures"] = 0;
List<string> PhotoFolders = new List<string>();
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\Dept1");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept2");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept3");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept4");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept5”);
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept6");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept7");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept8");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept9");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept10");
PhotoFolders.Add("\\\\intranet.org\\Photo Album\\Employees\\ Dept11");
Session["AllPhotoFolders"] = PhotoFolders;
List<string> AllPhotoFolders = (List<string>)Session["AllPhotoFolders"];
foreach (string folder in AllPhotoFolders)
{
DirSearch(folder);
}
Session["AllPhotoFiles"] = photoFileList;
Image1.ImageUrl = photoFileList[0].Replace("\\", "//");
var list = (List<string>)Session["AllPhotoFiles"];
lblName.Text = System.IO.Path.GetFileName(list[0]).Substring(0, System.IO.Path.GetFileName(list[0]).Length - 4).Replace("_", " ");
Session["CountOfPictures"] = photoFileList.Count;
}
}
void DirSearch(string sDir)
{
foreach (string f in Directory.GetFiles(sDir, "*.JPG"))
{
//BulletedList1.Items.Add(f);
photoFileList.Add(f);
}
foreach (string d in Directory.GetDirectories(sDir))
{
if (!d.EndsWith("_t") && !d.EndsWith("_w"))
{ DirSearch(d);}
}
}
protected void btnNext_Click(object sender, EventArgs e)
{
int NextIndex = (int)Session["index"];
int PictureCount = (int)Session["CountOfPictures"];
NextIndex += 1;
if (NextIndex == PictureCount)
{
NextIndex = 0;
}
Session["index"] = NextIndex;
var list = (List<string>)Session["AllPhotoFiles"];
Image1.ImageUrl = list[NextIndex].Replace("\\", "//");
lblName.Text = System.IO.Path.GetFileName(list[NextIndex]).Substring(0,System.IO.Path.GetFileName(list[NextIndex]).Length - 4).Replace("_"," ");
lblName.Visible = true;
}
protected void btnPrevious_Click(object sender, EventArgs e)
{
int NextIndex = (int)Session["index"];
int PictureCount = (int)Session["CountOfPictures"];
NextIndex -= 1;
if (NextIndex == -1)
{
NextIndex = PictureCount - 1;
}
Session["index"] = NextIndex;
var list = (List<string>)Session["AllPhotoFiles"];
Image1.ImageUrl = list[NextIndex].Replace("\\", "//");
lblName.Text = System.IO.Path.GetFileName(list[NextIndex]).Substring(0, System.IO.Path.GetFileName(list[NextIndex]).Length - 4).Replace("_", " ");
lblName.Visible = true;
}
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<table>
<tr>
<td><asp:Image ID="Image1" runat="server" Height="400px" Width="400px" /></td>
<td> </td>
<td><asp:Label ID="lblName" runat="server" Text="Label" Font-Size="X-Large"></asp:Label></td>
</tr>
<tr > <td>
<div style="text-align:center"> <asp:Button style="text-align:center" ID="btnPrevious" runat="server" Text="Previous"
onclick="btnPrevious_Click" Width="125px" />
<asp:Button style="text-align:center" ID="btnNext" runat="server" Text="Next" onclick="btnNext_Click"
Width="125px" /></div></td></tr>
</table>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
答案 0 :(得分:3)
我想我已经重现了这个问题。
您没有将http:添加到网址,而您正在加倍斜杠。代码似乎会生成如下输出:
<img src="////intranet.org//image//path//some_image.jpg">
这实际上似乎适用于Firefox和Chrome,但不适用于IE。问题不在于文件夹/文件名之间的双斜线,而是它们中的四个。
删除双斜杠(替换文件路径中的每个反斜杠),正如我在评论中建议的那样,应该解决它。还要考虑在网址中添加“http:”,以便正确形成。