Thursday, August 7, 2008

Read SWF File As Byte Array

By using the following function we can Read the SWF File as Byte Array

byte[] data= File.ReadAllBytes("Path of the file")
//Save SWF File in Specified Path
string path = "D:\\SWFFiles\\test.swf";
string dirPath = path.Remove(path.LastIndexOf("\\"), (path.Length - path.LastIndexOf("\\")));
if (!Directory.Exists(dirPath))
{
Directory.CreateDirectory(dirPath);
}
using (BinaryWriter binWriter = new BinaryWriter(File.Open(path, FileMode.OpenOrCreate)))
{
binWriter.Write(data);
}

Write Image in Browser C#

using System.IO;
using System.Text;
using System.Xml;

protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "image/jpeg";
Response.Clear();
Response.BufferOutput = true;
//Read the Image in Byte Array
byte[] data= File.ReadAllBytes("Path of the Image");
//Write the Image in Browser
using (MemoryStream stream = new MemoryStream(data))
{
stream.WriteTo(Response.OutputStream);
}
}