Solved

Create a Virtual File using MemoryStream

Posted on 2012-03-22
7
438 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

734 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