Hello All,
I am getting the below error on loadDocumentDescription
api on
using (PngViewer pngViewer = new PngViewer(documentGuid, cache, GetLoadOptions(password)))
{
loadDocumentEntity = GetLoadDocumentEntity(loadAllPages, documentGuid, fileCacheSubFolder, pngViewer);
}
private static LoadDocumentEntity GetLoadDocumentEntity(bool loadAllPages, string documentGuid, string fileCacheSubFolder, ICustomViewer customViewer)
{
if (loadAllPages)
{
customViewer.CreateCache();
}
dynamic viewInfo = customViewer.GetViewer().GetViewInfo(ViewInfoOptions.ForHtmlView()); //on this line
LoadDocumentEntity loadDocumentEntity = new LoadDocumentEntity();
if (!Directory.Exists(cachePath))
{
Directory.CreateDirectory(cachePath);
}
TryCreatePagesInfoXml(fileCacheSubFolder, viewInfo, out string pagesInfoPath);
foreach (Page page in viewInfo.Pages)
{
PageDescriptionEntity pageData = GetPageInfo(page, pagesInfoPath);
if (loadAllPages)
{
pageData.SetData(GetPageContent(page.Number, documentGuid, cachePath));
}
loadDocumentEntity.SetPages(pageData);
}
loadDocumentEntity.SetGuid(documentGuid);
return loadDocumentEntity;
}
this was working and suddenly stopped working, I checked but there is no code change
Below is the error →
Specified content type is not supported: application/vnd.openxmlformats-officedocument.wordprocessingml.document.
12-20-2023 Bug List.docx (2.4 MB)
@Niteen_Jadhav
Thank you for sharing the source file and code you’re using. We’ll investigate this issue and update you.
Hello,
I have some findings which might help you.
I am storing the document on my system and passing the path to viewer.
I changed that approach, previously I used to store the file as it is but now I am using chunk to store the file and after that it stopped working below is the codes for your reference.
//Not Working with the below code
try
{
const int chunkSize = 1024 * 1024; // 1 MB
string fileUploadPath = System.IO.Path.Combine(Program.GetTempFolderPath(), "FileUpload");
bool exists = System.IO.Directory.Exists(fileUploadPath);
if (!exists)
{
System.IO.Directory.CreateDirectory(fileUploadPath);
}
string uniqueFileName = Guid.NewGuid().ToString(); // Generate unique file name
string filePath = System.IO.Path.Combine(fileUploadPath, uniqueFileName);
using (Stream outputStream = new FileStream(filePath, FileMode.Create))
{
byte[] buffer = new byte[chunkSize];
int bytesRead;
while ((bytesRead = await HttpContext.Current.Request.InputStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
await outputStream.WriteAsync(buffer, 0, bytesRead);
}
}
string ext = Path.GetExtension(uniqueFileName).ToLowerInvariant();
string fileExtension = null;
if (!String.IsNullOrWhiteSpace(uniqueFileName))
{
fileExtension = ext;//originalFileName.Split('.');
}
if (!String.IsNullOrWhiteSpace(fileExtension))
{
BusinessLayer.IBulkDataUpload.IBulkDataUpload obj = (BusinessLayer.IBulkDataUpload.IBulkDataUpload)DALFinder.GetInstance(typeof(BusinessLayer.IBulkDataUpload.IBulkDataUpload));
string fileExt = "";
if (fileExtension.Contains("."))
{
fileExt = fileExtension;
}
else
{
fileExt = "." + fileExtension;
}
BusinessEntities.BulkUpload.FileTypeExtension resObj = await obj.GetDocTypeFileTypeMapExtension(0, fileExt);
if (String.IsNullOrWhiteSpace(resObj.Extension))
{
uniqueFileName = "-1";
}
}
return uniqueFileName;
}
catch (Exception ex)
{
Utils.Logger.Instance.LogException(ex);
return "";
}
//working with the below code
try
{
string fileuploadPath = System.IO.Path.Combine(Program.GetTempFolderPath(), "FileUpload");
bool exists = System.IO.Directory.Exists(fileuploadPath);
if (!exists)
{
System.IO.Directory.CreateDirectory(fileuploadPath);
}
MultipartFormDataStreamProvider provider = new MultipartFormDataStreamProvider(fileuploadPath);
StreamContent content = new StreamContent(HttpContext.Current.Request.GetBufferlessInputStream(true));
foreach (KeyValuePair<string, IEnumerable<string>> header in Request.Content.Headers)
{
content.Headers.TryAddWithoutValidation(header.Key, header.Value);
}
await content.ReadAsMultipartAsync(provider);
string uploadingFileName = provider.FileData.Select(x => x.LocalFileName).FirstOrDefault().Replace(fileuploadPath, "").TrimStart('\\');
string originalFileName = (provider.Contents[0].Headers.ContentDisposition.FileName).Trim(new char[] { '"' });
string ext = Path.GetExtension(originalFileName).ToLowerInvariant();
string fileExtension = null;
if (!String.IsNullOrWhiteSpace(originalFileName))
{
fileExtension = ext;//originalFileName.Split('.');
}
if (!String.IsNullOrWhiteSpace(fileExtension))
{
BusinessLayer.IBulkDataUpload.IBulkDataUpload obj = (BusinessLayer.IBulkDataUpload.IBulkDataUpload)DALFinder.GetInstance(typeof(BusinessLayer.IBulkDataUpload.IBulkDataUpload));
string fileExt = "";
if (fileExtension.Contains("."))
{
fileExt = fileExtension;
}
else
{
fileExt = "." + fileExtension;
}
BusinessEntities.BulkUpload.FileTypeExtension resObj = await obj.GetDocTypeFileTypeMapExtension(0, fileExt);
if (String.IsNullOrWhiteSpace(resObj.Extension))
{
uploadingFileName = "-1";
}
}
return uploadingFileName;
}
catch (Exception ex)
{
Utils.Logger.Instance.LogException(ex);
return "";
}
@Niteen_Jadhav
Thank you for adding the code that does not work. It seems that you’re saving a file without extension.
// code that does not work
string uniqueFileName = Guid.NewGuid().ToString(); // Generate unique file name
//..
string ext = Path.GetExtension(uniqueFileName).ToLowerInvariant(); // <==== `ext` will always be empty string because `uniqueFileName` is GUID e.g. 9ad976b1-5140-4e04-93e5-15d5e7242044
string fileExtension = null;
if (!String.IsNullOrWhiteSpace(uniqueFileName))
{
fileExtension = ext;//originalFileName.Split('.');
}
When you pass a file path where file does not have extension Viewer tries to detect the file type by the content and sometimes it may fail like in this case.
Try adding extension when you saving a file and it should fix the issue. In case you don’t want to add extension you can specify file type in load options.
Please let us know if it works for you.