Solved

Create a Virtual File using MemoryStream

Posted on 2012-03-22
7
436 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

763 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