Мне нужно отобразить документ, сохраненный на сервере SQL в формате varbinary (max). В предыдущей версии страницы на странице отображался один документ, метод, который извлекает документ и отображает его на странице, вызывался в методе Page_Load, и он работал.
protected void Page_Load(object sender, EventArgs e) {
...
int codeSiteId = -1;
long docId = -1;
if (!string.IsNullOrEmpty(qs["codesiteid"]))
{
if (!Int32.TryParse(qs["codesiteid"], out codeSiteId))
{
return;
}
}
//else return;
if (!string.IsNullOrEmpty(qs["docid"]))
{
if (!Int64.TryParse(qs["docid"], out docId))
{
return;
}
}
ShowDocumentModel(docId, codeSiteId);
...
}
protected void ShowDocumentModel(long documentModelId, int codesiteid)
{
string temppath = helpsi.framework.core.Configurator.Instance.getAppSettingsValue("APP_REGISTRATION_TEMP_PATH", codesiteid);
string filename="";
string pdffile = string.Empty;
try
{
documentLoading.Visible = true;
string path = Path.GetFullPath(Server.MapPath(temppath));
helpsi.framework.core.CustomerProvider.DocumentModelResult result = helpsi.framework.core.CustomerProvider.DocumentModel.GetDocumentModelContent(documentModelId);
if (!string.IsNullOrEmpty(result.FileName))
{
string unescapeFileName = HttpUtility.UrlDecode(result.FileName);
/*unescapeFileName = unescapeFileName.Replace("<", "").Replace(">", "").Replace("+", "").Replace("{", "").Replace("}", "").Replace("/", "");
*/
string[] blackList = {"<", ">", "\\+", "{", "}", "/","\\*", ":" };
for (int i = 0; i < blackList.Length; i++)
{
unescapeFileName = System.Text.RegularExpressions.Regex.Replace(unescapeFileName, blackList[i], "", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
}
filename = Path.Combine(path, unescapeFileName.Replace(" ", "").ToLower());
File.WriteAllBytes(filename, result.Content);
descDocumentModel.InnerText = result.DescDocumentModel;
descDocumentModelState.Attributes.Add("i18n", result.DocumentModelState);
descDocumentModelType.Attributes.Add("i18n", result.DocumentModelType);
documentModelUploadDate.InnerText = PageUtil.jsonString(result.UploadDate.ToString("s"), HttpContext.Current);
switch (result.ContentType.Split('/')[0])
{
case "image":
hfTypeFile.Value = "image";
hfImageFile.Value = Page.ResolveUrl(Path.Combine(temppath, Path.GetFileName(filename))); ;
break;
default:
string ext = Path.GetExtension(filename);
if (ext.Equals(".rtf", StringComparison.CurrentCultureIgnoreCase) || ext.Equals(".doc", StringComparison.CurrentCultureIgnoreCase) || ext.Equals(".docx", StringComparison.CurrentCultureIgnoreCase))
{
if (!PdfConverter.ConvertDocToPdf(filename, Server.MapPath(temppath), codesiteid, out pdffile))
pdffile = Path.GetFileName(filename);
}
else
{
pdffile = Path.GetFileName(filename);
}
pdffile = Page.ResolveUrl(Path.Combine(temppath, Path.GetFileName(pdffile)));
previewFile.Attributes["src"] = pdffile;
previewFile.Visible = true;
break;
}
}
hfdocumentModelStateId.Value = helpsi.framework.core.CustomerProvider.DocumentModel.get<helpsi.framework.core.CustomerProvider.DocumentModel>(documentModelId).CODE_DOCUMENT_MODEL_STATE_ID.ToString();
hfdocumentModelId.Value = documentModelId.ToString();
}
catch (Exception ex)
{
throw;
}
finally
{
documentLoading.Visible = false;
}
}
На странице есть iframe для отображения предварительного просмотра документа
<div class="ui-layout-center">
<div class="wrapper" runat="server" id="content">
<div id="viewerDocs" style="height:100%;width:100%">
<img id="documentLoading" src="../images/loadsmall.gif" border="0" runat="server" visible="false"/>
<iframe id="previewFile" src="about:blank" width="100%" height="551" frameborder="0" runat="server" visible="true"></iframe>
</div>
<div class="imgViewver">
<div id="viewer" class="viewer"></div>
</div>
</div>
</div>
Теперь страница изменилась, потому что больше нет ни одного документа, но есть больше документов, и отображаются детали этих документов в сетке. Предварительный просмотр документа не отображается при загрузке страницы, но при нажатии на элемент сетки предварительный просмотр документа должен отображаться в iframe. Есть способ сделать это с помощью jQuery, возможно, преобразовав ShowDocumentModel в вызов ajax? Спасибо