Free Support Forum - groupdocs.com

.NET Comparison custom UI


#1

I’ve downloaded your C# WebForms demo and I’m seeing the following code on the Default.aspx page.


<%= GroupdocsComparison.Comparison("#comparison-wrapper")
.SourceFileName(“Tables.Source.docx”)
.TargetFileName(“Tables.Target.docx”)
.ResultFileName(“Redline.docx”)
.ImmediateCompare()
%>

I understand that you’re populating the comparison -wrapper div with the contents of the Redline.docx to the page as an image.

I’d like to completely remove all code from the ASPX page and do everything in a code behind file. How do I go about doing this so that everything is from memory (I see I can load the source and target file from a stream but I can’t do the same for the result file name).

I’ve modified the files to have the following code:
Default.aspx
<asp:Content runat=“server” ID=“BodyContent” ContentPlaceHolderID=“MainContent”>
</asp:Content>

Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
ClientHelper clientHelper = GroupdocsComparison.Comparison("#comparison-wrapper");
clientHelper.SourceFileName(String.Empty, new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Tables.Source.docx"))));
clientHelper.TargetFileName(String.Empty, new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Tables.Target.docx"))));

clientHelper.ResultFileName(“Redline.docx”);
clientHelper.ImmediateCompare();
}

But I’m getting the following error which comes from the Site.Master file:

The comparison ‘Undefined’ is not supported.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Groupdocs.Comparison.Exceptions.ComparisonException: The comparison ‘Undefined’ is not supported.

Source Error:

Line 22:
Line 23: <asp:PlaceHolder ID=“PlaceHolder2” runat=“server”>
Line 24: <%: GroupdocsComparison.CreateScriptsLoadBlock().UseHttpHandlers() %>
Line 25: </asp:PlaceHolder>
Line 26:

Source File: c:\Program Files (x86)\GroupDocs\Comparison 2.0 for .NET\Samples\GroupDocsComparisonWebFormsDemo\Site.Master Line: 24

Stack Trace:

[ComparisonException: The comparison ‘Undefined’ is not supported.]
Groupdocs.Comparison.ComparisonFactory.CreateHtmlComparison(IComparisonResult result, Context context, ComparisonType comparisonType) +123
Groupdocs.Comparison.ComparisonFactory.CreateComparison(IComparisonResult result, Context context, ComparisonType comparisonType) +91
Groupdocs.Comparison.ComparisonFactory.Create(Context context) +105
Groupdocs.Comparison.ComparisonApiFacade.Compare(Context context, ProgressDelegate progressDelegate) +16
Groupdocs.Web.UI.Comparison.ComparisonService.Compare() +325
Groupdocs.Web.UI.Comparison.ClientHelper.GenerateClientCode() +34
Groupdocs.Web.UI.Comparison.ClientScriptLoaderHelper.ToString() +1585
Groupdocs.Web.UI.Comparison.ClientScriptLoaderHelper.System.Web.IHtmlString.ToHtmlString() +9
System.Web.HttpUtility.HtmlEncode(Object value) +38
ASP.site_master.__RenderPlaceHolder2(HtmlTextWriter __w, Control parameterContainer) in c:\Program Files (x86)\GroupDocs\Comparison 2.0 for .NET\Samples\GroupDocsComparisonWebFormsDemo\Site.Master:24
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +268
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +128
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +8
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +57
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +100
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1386

If I remove this line from the Site.Master file, the page renders but it’s completely blank.

#2

Hello Miles,

Thank you for detailed description of your problem. We checked your code and found that you use empty string as parameter in this code:
clientHelper.SourceFileName(String.Empty, new MemoryStream…

You cannot specify a null or empty string (“String.Empty” in your case) as file name because in such case GroupDocs.Comparison will not be able to create a file with such name. You should use a correct and unique file name that contains only allowed characters.

This statement is related to all: SourceFileName, TargetFileName and ResultFileName: all of these must be correct and unique file names.

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


#3

Thank you Denis. I’ve now modified my code to be the following and everything compiles and runs as expected.


ClientHelper clientHelper = GroupdocsComparison.Comparison("#comparison-wrapper");
clientHelper.SourceFileName(“Test1.docx”, new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Tables.Source.docx"))));
clientHelper.TargetFileName(“Test2.docx”, new MemoryStream(System.IO.File.ReadAllBytes(Server.MapPath("~/App_Data/Tables.Target.docx"))));
clientHelper.ResultFileName(“Redline.docx”);
clientHelper.ImmediateCompare();

My last issue is how do I get the result file without writing it to disk? Can I not save it to a stream?

#4

Hello Miles,


Thank you for coming back. We are glad to hear that the issue was resolved.

Regarding to your last question about writing result file to disk - unfortunately you can’t avoid this with current version of GroupDocs.Comparison. That's why you need to set up GroupdocsComparison.SetRootStoragePath" in the Global.asax

But we have plans to add possibility to work with memory i.e. you will be to avoid write/read to disk. This will be released in about a month. So please stay tuned and check new releases for this feature.