Solved

Create a Virtual File using MemoryStream

Posted on 2012-03-22
7
419 Views
Last Modified: 2012-04-05
I want to create a Virutal File using MemoryStream so I don't have to create an actual file to the Web Server.

I would like to create this Virtual File with HTML Text (string) and then take that Virtual File and pass it to a JavaScript Window.Open to display for the operator to print.

Thanks,
Mark
0
Comment
Question by:smithmrk
  • 4
  • 3
7 Comments
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37753526
you can do something like

In jquery,write script which should fire on button click or any other event

$( ".selector" ).dialog({
   open: function(event, ui) {
     $('#divInDialog').load('test.html', function() {
       alert('Load was performed.');
     });
   }
});
Basically, you create your dialog, and when it is opened, an html file is loaded from your server, replacing the contents of your <div id="divInDialog"></div>, which should be inside your dialog <div class="selector"/>.

If you want your data dynamically then, create a handler/Web service and code it to return a html encoded string.Then from Client side(jquery) , make a ajax call to the server,and replace the html content(received from the server) with the div content like as follows

$("#YourDivName").html(YourServerReturnedHtmlString);

Hope, this will resolve your issue.
0
 

Author Comment

by:smithmrk
ID: 37753555
My main issue is creating the HTML File Virtually NOT a Real File written to the Server.
How do I create an HTML File in Memory?

Thanks,
Mark
0
 
LVL 7

Expert Comment

by:Lalit Chandra
ID: 37753659
Mark  you don't have to create the html file in the memory of the server.
Suppose , i want to get data from anywhere like database or xml. lets say DataTable.
ok,Now create a string something like as follow


StringBuilder s = new StringBuilder();
s.append("<table>");
 forEach(DataRow dr in Datatable.Rows)
{
    s.append("<tr><td>").append(dr[1].toString()).append("</td></tr>");
}
s.append("</table>");

Now,  you have ended your data wrapped inside the string.So, you can simple send this string to the Client (i,e jquery ajax call), and there append this html string to the div and display the pop us, as i have mention in my previous answer.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:smithmrk
ID: 37753715
First THANK YOU VERY MUCH FOR HELPING ME!!!

Second...not so good with C# using VB

Thrid...Call me crazy or new at this...but here is what I'm really trying to do.

http://www.codeproject.com/Articles/14367/Email-Templates

I found this code that takes an HTM File that is already created with variables that are replaced with acutal data when done I end up with an HTML String.  Works GREAT for e-mail and so I wanted to expand on this code to design a template that I could fill with variable Pop it up in a Window for printing instead of e-mailing.

I need a way to take the HTML String (text) and pass it to something that will Popup a window that the user can print.

This code does allow me to write the HTML Text out to a file...but I don't want to later have to clean up these files...so I was hoping I could just pass the HTML Text to something that would create a Popup Window for printing.

Thanks,
Mark
0
 
LVL 7

Accepted Solution

by:
Lalit Chandra earned 500 total points
ID: 37753776
Ok , In the same way, just create a dialog box (as sugested in my first solution above),and then get a ajax call to the server,get the response as the Html string,and then place that section to the div. Now use the following sample code to print that specific part only.

<script type="text/javascript">

function printSelection(node){

  var content=node.innerHTML
  var pwin=window.open('','print_content','width=100,height=100');

  pwin.document.open();
  pwin.document.write('<html><body onload="window.print()">'+content+'</body></html>');
  pwin.document.close();
 
  setTimeout(function(){pwin.close();},1000);

}
</script>

<div id="test">
this is a test

</div>

<a href="" onclick="printSelection(document.getElementById('test'));return false">print</a>

Hope, this will fix it.
0
 

Author Comment

by:smithmrk
ID: 37753952
OK...first I need to create the MyParse.Parse from my Code Behind then I found this code...but haven't been able to get it to work, but is very similar to what you posted above.

Please call the javascript to pop a new window and write the html into it.

           function PopUpWindow(string html)
        {
            OpenWindow=window.open("url", "newwin", "height=500, width=500,toolbar=no,scrollbars=yes,menubar=no");
            OpenWindow.document.write(html);
        }


What I would like is to be able to pass my HTML Text (String) to this function somehow.

This is What I have so far but isn't working I need a virtual type file to pass in where it shows MyParser.Parse

        If Not ClientScript.IsClientScriptBlockRegistered(Me.GetType(), "PopUpWindow") Then

            ClientScript.RegisterClientScriptBlock(Me.GetType(), "PopUpWindow", "function PopUpWindow(){" & _
            vbCr & vbLf & "         OpenWindow=window.open('url', 'newwin', 'height=500, width=500,toolbar=no,scrollbars=yes,menubar=no');" & _
            vbCr & vbLf & "         OpenWindow.document.write('" & MyParser.Parse & "');}", True)

            ClientScript.RegisterStartupScript(Me.GetType(), "PopUpWindow", "PopUpWindow();", True)
        End If


This works as far as Popping up a window, but shows an error message because it doesn't know how to read my HTML String I guess.

Mark
0
 

Author Closing Comment

by:smithmrk
ID: 37813105
OK I was able to figure it out using MyParser code and this sample.

Thanks,
Mark
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now