CastroHenriques

This is my blog

CarlosCH – New Website

In this website i provide you free simple applications.

Current application:

  • 3Mail – Easy Email Client;
  • Download Manager – Application for you manage your downloads;
  • Leca Webcam – This application provide you a online webcam in live
  • Router Password Recover – This application help you getting the password of Thomson Routers

 

Visite my website in http://carlosch.pt.la/

Generating and downloading an XPS document using ASP.NET

Windows Presentation Foundation includes a new API for generating XPS documents. This article describes the steps involved in generating an XPS document on the server side of an ASP.NET web application using WPF and sending the resulting document to the client browser.

What we need to do is create a flow document, convert it to XPS and send it to the client.

 

STEP 1 – CREATING A FLOWDOCUMENT ON THE SERVER

Creating a FlowDocument object from scratch is as simple as calling the constructor:

FlowDocument flowDocument = new FlowDocument();

This gives us an empty FlowDocument that we can fill with content. The content is represented by a collection of Blocks. Filling the Blocks collection manually will probably suffice for very simple documents

Paragraph p1 = new Paragraph();
p1.Inlines.Add("This is the text");
p1.Inlines.Add("of the first paragraph");
Section section1 = new Section(p1);
flowDocument.Blocks.Add(section1);

 

but in a real project, we will most likely need some kind of a FlowDocument generator and/or have a predefined document template that we will fill with data. The natural format for such template is a XAML file.
<FlowDocument xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
              xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
  <Section>
    <Section FontFamily="Times New Roman">
      <Paragraph Fontcolor: rgb(139, 0, 0);">18" FontWeight="Bold" >@placeholder1</Paragraph>
      <Paragraph Fontcolor: rgb(139, 0, 0);">10">
        @placeholder2
        Lorem ipsum dolor sit amet, consectetur adipisicing elit,
        sed do eiusmod tempor incididunt ut labore et dolore
        magna aliqua.
      </Paragraph>
    </Section>
</FlowDocument>

@placeholder1 and @placeholder2 will later be replaced by live data.

The template file can be saved (for example) as a global resource and later accessed by calling

string pageTemplate = (string)HttpContext.GetGlobalResourceObject("Resources", "MyTemplate");

Now that we have the template in memory as a string, it is a good time to replace the placeholders with real data and convert the final template to a real FlowDocument object

pageTemplate = pageTemplate.Replace("@placeholder1", MyData1);
pageTemplate = pageTemplate.Replace("@placeholder2", MyData2);
FlowDocument flowDocument = (FlowDocument)XamlReader.Parse(pageTemplate);

The placeholder replacement process is really lame here, but you get the point…

At this point, we have a filled-in FlowDocument object in memory ready to be converted to XPS.

 

STEP 2 – CONVERTING A FLOWDOCUMENT TO AN (IN-MEMORY) XPS FILE

We start with a FlowDocument object and end up with an XPS file saved as an array of bytes. A code snippet is worth a thousand words here:

public static byte[] FlowDocumentToXPS(FlowDocument flowDocument, int width, int height)
{
    MemoryStream stream = new MemoryStream();

    // create a package
    using (Package package = Package.Open(stream, FileMode.Create))
    {
        // create an empty XPS document            
        using (XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum))
        {
            // create a serialization manager
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);
            // retrieve document paginator
            DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator;

            // set page size
            paginator.PageSize = new System.Windows.Size(width, height);       
            // save as XPS
            rsm.SaveAsXaml(paginator);
            rsm.Commit();
        }
        return stream.ToArray();
    }
}

 

STEP 3 – SENDING AN IN-MEMORY FILE TO THE CLIENT BROWSER

If we want to generate the XPS file (or any other kind of file) based on a client request, it is very inconvenient to have to save the file on the server and give the client its URI.

What we will do instead is create a hidden form on the web page and send the XPS file to the client as a response to submitting this form.

The hidden form can be very simple, all we need to include is the parameters that specify the XPS (or other) file to retrieve.

<form id="generateFileForm" action="DownloadFile.aspx" method="post">
    <input runat="server" type="hidden" id="id" />
</form>

Once we fill in the “id” parameter and submit the form

HtmlDocument doc = HtmlPage.Document;
HtmlElement id = doc.GetElementById("id");
id.SetAttribute("value", MyDocumentId);
doc.Submit("generateFileForm");

the code-behind of DownloadFile.aspx then does the trick

public partial class DownloadFile : System.Web.UI.Page
{
    [StaSyncOperationBehavior]
    protected void Page_Load(object sender, EventArgs e)
    {
        string sid = Request.Form["id"];     
        byte[] bytes = GetXpsFileBytes(sid);
        Response.Clear();
        Response.ContentType = "application/octet-stream";
        Response.AddHeader("Content-Disposition", "attachment; filename=document.xps");
        Response.OutputStream.Write(bytes, 0, bytes.Length);
        Response.Flush();
        Response.Close();
    }
}

 

The [StaSyncOperationBehavior] attribute was developed by Scott Seely and you can read about it here. UPDATE: The blog no longer seems to work, but here is the source code for the attribute.
To ensure that the response generation runs on a STA thread, we also need to set the AspCompat attribute on the DownloadFile.aspx page like this

<%@ Page AspCompat="true" Language="C#" AutoEventWireup="true" CodeBehind="DownloadFile.aspx.cs" Inherits="MyNamespace.DownloadFile" %>

 

CONCLUSION

The good thing about this solution is that nothing is saved to disk on the server side and that the client page does not reload when requesting the document, which means that you can happily use it to generate and download documents in Silverlight applications.

I hope this experience of mine will be useful to someone and if you have any questions or comments, please let me know in the discussion.

 

Posted by: http://blog.jaroslavklima.com

Phishing Attacks and Hoax

A wave of phishing attacks have been hitting over the last day targeting customers of Regions Bank in the United States and Westpac Bank customers in New Zealand. Other banks in the US, UK and Australia are also being targeted.

The ones I have been investigating all include a HTML document as an attachment with a form to fill out.

Some purport to be a survey for you to fill out and be paid $35 for participating, while others say your account has been suspended until you verify your identity.

When the victim opens the attachment it prompts them to answer some survey questions and provide some of the following details:

  • Social Security Number
  • Card number
  • Card expiration
  • CVV
  • ATM PIN
  • First, Middle and Last name
  • Email (ironically they mailed you the form)
  • Address
  • Mother’s maiden name
  • Place of birth
  • Birthday
[…] Link for full article: here
My warning!
Beware of emails sent by the bank.
If your bank never sent an email asking for information, check with your bank first before making any decisions. There is no exchange of information via email that requires the transfer of personal data. In the video below i show you how easy is creating a simple hoaxwith an application that I developed. This phishing attack exist in all world.
You can download the Hoax Creator RC in my Website: Carlosch.com
Creating a Hoax
If you found my application for download please read this:
Warning!This tool is only for system testing and see if people are able to detect Social Engineering and Phishing.Please do not use it for other purposes.Thanks for watchingCarlosCH.COM


Warning!

Now my post on Windows programming will be made in VB.Net.

How to create a VM Machine using Partition

For this tutorial i use VMware Workstation 7.1.5 build-491717 on Windows 7.

Target:Virtualaze Linux Ubuntu 10.04

  • Have a Hard Disk with 2 partition in this case is (Windows 7 and Linux Ubuntu 10.04)
  • In Windows 7 install the VMware Workstation 7.1.5
  • Create a new virtual machine (follow the video below)
  • Start the Virtual Machine and select Linux Ubuntu in the Grub
  • Its Done!
I hope this help you!
Send me a comment if you have a question

Mac Low Cost

If you are like me you would like to have a Machintosh, but you dont have the money to buy one, so I discover 2 ways to have a “Low Cost Mac”.

First Way:

– Install Linux and download a Mac Theme

  • Install Linux Ubuntu 10.04 (like you see in the folowing video)

Second Way:

– Use a iBoot

  • This way I will not explain, i just provide you the link to visit : Link
The second way does not have many compatibility and often there are errors, because the installation was not done in proper way, and a thousand and one reasons. If they wish toinvestigate further about the second way to search google for Hackintosh (Google is your friend, but I also am).
I advise first, always Linux 😀
Any question set up a comment…

National Vulnerability Database

I recommend this website:

NVD

http://nvd.nist.gov/

For example:

I search for Adobe, one of the records i found have de id: CVE-2011-2430 and have this info:

Summary: Adobe Flash Player before 10.3.183.10 on Windows, Mac OS X, Linux, and Solaris, and before 10.3.186.7 on Android, allows remote attackers to execute arbitrary code via crafted streaming media, related to a “logic error vulnerability.”

Published: 09/22/2011
CVSS Severity9.3 (HIGH)
This website has many uses, can be used for good and for evil. We should visit it regularlyin order to defend our systems / companies / software / website / etc …

Nimda, Lion security hole – 60 Sec Security

600,000+ compromised account logins every day on Facebook

If an unauthorised party has logged into your Facebook account, then you’re far from alone.

New official statistics revealed by the social networking giant reveal that 0.06% of the more than billion logins that they have each day are compromised.

Put another way, that’s more than 600,000 per day – or, if you really like to make your mind melt, one every 140 milliseconds. (By comparison, a blink of the eye takes 300-400 milliseconds)

The statistic was revealed in an infographic published alongside an official Facebook blog post trumpeting new security features introduced by the firm.

 

Full post in here

Mac iBook G4 – Boot from USB

– Plug in the USB device where you have copied your bootable system to.
– Power on your iBook and hold down Command+Option+O+F. This will take you into the OpenFirmware.
– Once you see the screen go white with some text on it, you can release the keys in the previous step.
– Type “boot ud:,\\:tbxi”
– If after this command you pc dont start booting from the usb you must to type one of the next lines:
– boot usb0/disk@1:,\\:tbxi
– boot usb1/disk@1:,\\:tbxi