Solved

Create a Virtual File using MemoryStream

Posted on 2012-03-22
7
424 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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 Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

896 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

11 Experts available now in Live!

Get 1:1 Help Now