Downloading the converted file

Hi!,

How can I download the converted file directly instead of a zip file.

What are the parts that needs to be modified in the code given in
https://docs.groupdocs.com/display/conversionnet

to fix this.

Thanks,
Srinath

Hello Srinath,

We are very sorry - “How to use GroupDocs Conversion for .NET in an ASP.NET MVC Project” article was incomplete and “Download” method was missing. Now the article was updated (see item #4) and works fine. This method allows you to download output (converted) file from the server to the client-side.

If you will have more questions please feel free to contact us.

Hi,

can you please tell me how to get the download links for each converted file instead of a single link to download the zip?

Thanks,
Srinath

Hello Srinath,

If you are using the article “How to use GroupDocs.Conversion for .NET in an ASP.NET MVC Project” (we mentioned it earlier) or sample project “GroupDocsConversionMVCDemo” from Official Samples, which has the same code as in the article, there is no way to obtain ZIP archive. The only file that you can download is pure converted file, without ZIP. Take a look at this code yourself - there is no code which collects converted documents and archives them to the ZIP.

Maybe you are using some other project. In such case please provide this project or at least its part.

Please notify us if you will have any issues or questions, we will be glad to help you.

Hi,

I tried your solution. It worked. the download is no longer a zip file. But the converted file is damaged. it can’t be open.
Please let me know how to fix this.
You can get the project code from the following link.

https://www.dropbox.com/s/s5rohm7q98k9c33/converson%20-%20Copy.rar

Thanks,
Srinath


Hello Srinath,

We are sorry to hear that you have such issue. We downloaded and reviewed your project. There are numerous errors inside it that are not related to GroupDocs.Conversion.

1. Class “HomeController”, second overload of “Index” method, lines 64-84. These conditions will never be succeeded because “tr” variable has “.ext” format, while you checking it for “ext” format.

2. The same class and method, lines 105-203. All this code is completely broken and invalid, because every time, when you invoke “conversion_service.Convert(Groupdocs.Common.FileType.Jpg).Result”, new conversion is performed. Actually, I don’t understand why you have cloned the same block of code 7 times. Each block has the same exact source code. Output files are not “corrupted” - they simply have improper extension. “response.End();” stops processing of the response, so the first successful conversion will be the last, but not the desired. Doesn’t matter which format user will select in the drop down list, output format will be the first from the list.

I rewrote yours code and made it correct.


String ext = tr.TrimStart(new char[1] { ‘.’ });
ConversionJobResult res;
if (ext.ToString() == “jpg”)
{
res = conversion_service.Convert(Groupdocs.Common.FileType.Jpg);
}
else if (ext.ToString() == “csv”)
{


res = conversion_service.Convert(Groupdocs.Common.FileType.Csv);
}
else if (ext.ToString() == “doc”)
{
res = conversion_service.Convert(Groupdocs.Common.FileType.Doc);
}
else if (ext.ToString() == “docx”)
{


res = conversion_service.Convert(Groupdocs.Common.FileType.Docx);
}
else if (ext.ToString() == “pdf”)
{


res = conversion_service.Convert(Groupdocs.Common.FileType.Pdf);
}
else if (ext.ToString() == “txt”)
{


res = conversion_service.Convert(Groupdocs.Common.FileType.Txt);
}
else
{


res = null;
}
if (res != null && res.Result == true)
{


ViewBag.confile = res.ConvertedFileName;


System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;


response.ClearContent();


response.Clear();


String extension = Path.GetExtension(ViewBag.confile);


response.AddHeader(“Content-Disposition”, “attachment; filename=”" +

Path.GetFileName(res.ConvertedFileName) + “”");


response.TransmitFile(res.ConvertedFileName);


response.Flush();


response.End();
}
else
{


System.Web.HttpResponse response = System.Web.HttpContext.Current.Response;


response.StatusCode = 500;


response.StatusDescription = “Failed to convert document”;


response.End();
}

Insert this code right after “conversion_service.SetOutputFile(pathn);” line (No 63) and remove all others after it.

If you will have more questions please feel free to contact us.

Hi,

I tried your code. It worked. :slight_smile:

However there was an error when trying to convert some files.
eg:-xlsx to jpg , pdf to jpg, txt to jpg, doc to txt, docx to txt etc.

When trying to convert them, the browser gets stuck in a blank page.

I checked the folder where the converted files are saved. Files are there. But they seem to be damaged. I cannot open them.

Please tell me how to fix this issue.

Thanks,
Srinath

Hi there,


Thanks for this additional information. Our support crew are on leave today but will handle your request as soon as they return tomorrow. Your patience is greatly appreciated.

Thanks,
Adam