我现在在列表中有一些ppt文件,当我点击特定的ppt然后我生成每张幻灯片的图像并存储在一个文件夹中。现在我想显示列表中的所有图像。 这是我的html来显示图像。
<div class="sideBySide">
<div id="dvLeft" class="left" style="overflow: scroll; height: 400px; float: left">
</div>
<div class="right" >
<ul class="target connected" style="float: left; width: 300px"></ul>
</div>
</div>
这是我的剧本
$(".lnk").click(function (e) {
e.preventDefault();
var vPath = $(this).attr("href");
debugger;
//$("#viewPlaceHolder").load("/home/generateImageList?strPath=" + $(this).attr("href"));
//$(".left").html("/home/generateImageList?strPath=" + $(this).attr("href"));
//$("#iPPT").attr("src", $(this).attr("href"));
//---------------
$.ajax({
type: "POST",
data: { "strPath": vPath },
url: '@Url.Action("generateImageList", "home")',
success: function (result) {
alert(result);
$('#dvLeft').empty();
$('#dvLeft').html(result);
//$('.left').html("<ul class='source connected'><li>Audi</li></ul>");
$(".source, .target").sortable({
connectWith: ".connected"
});
}
});
//---------------
})
});
public ActionResult generateImageList(string strPath)
{
try
{
// load a PowerPoint document
PPTXDocument doc = new PPTXDocument(strPath);
//Delete files
System.IO.DirectoryInfo di = new DirectoryInfo(@"D:\Sajal\ResterEdgeApiTest\PPTSlider\Test\");
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
// convert all PowerPoint document pages/slides to PNG files
// page index will automatically append to the file name
doc.ConvertToImages(ImageType.PNG, @"D:\Sajal\ResterEdgeApiTest\PPTSlider\Test\", "0");
DirectoryInfo dirInfo = new DirectoryInfo(@"D:\Sajal\ResterEdgeApiTest\PPTSlider\Test\");
List<FileInfo> files = dirInfo.GetFiles().OrderBy((f) => Int32.Parse(Path.GetFileNameWithoutExtension(f.Name))).ToList();
List<clsPPT> ppts = new List<clsPPT>();
int i = 1;
/****************************/
StringBuilder sb = new StringBuilder();
sb.Append("<ul class='source connected' style='float: left'>");
/****************************/
foreach (var item in files)
{
clsPPT cp = new clsPPT();
cp.strName = item.Name;
string strPath1 = @"http://localhost:63714/Test/" + item.Name;
//Uri myuri = new Uri(strPath1);
cp.strPath = strPath1;//myuri;
cp.rowNo = i;
ppts.Add(cp);
sb.Append("<li><p>" + i.ToString() + "</p><img id='" + i + "' src='" + strPath1 + "' height='200' width='300' alt='" + strPath + "' /></li>");
i = i + 1;
}
sb.Append("</ul>");
ViewBag.htmlDesig = sb.ToString();
//return PartialView("~/Views/Home/_ppSlideList.cshtml", ppts);
//return PartialView("~/Views/Home/_ppSlideListNew.cshtml", ppts);
return Json(sb.ToString());
}
catch (Exception ex)
{
throw ex;
}
}
当我第一次点击ppt时,它正在加载正确的图像但是当我点击第二个ppt时,列表的图像生成和html生成成功,但它显示以前不存在int文件夹的图像。< / p>
答案 0 :(得分:0)
将 cache: false
添加到您的AJAX调用中,如下所示:
$.ajax({
type: "POST",
cache: false,
...
});