Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Create a Virtual File using MemoryStream

Posted on 2012-03-22
7
Medium Priority
?
449 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

715 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