February 2007 - Posts

Today the second part of my text editor (Rich Text Editor) is published.

Check it out at

http://aspalliance.com/1156

HC

Posted by haissam | with no comments

I was working on a project where i needed the user to download multiple files so i had the idea of zipping the folder and send it to the user.

Using the free library SharpZipLib ,  i could achieve this purpose.

// Code to Zip a Folder.

string sPath = Server.MapPath("~") + "DownloadFolder";

string sPath = Server.MapPath("~") + "DownloadFolder";
string zipFullPath = Server.MapPath("~") + "DocumentFolder.zip";

ZipOutputStream zipOut = new ZipOutputStream(File.Create(zipFullPath));

foreach(string fName in Directory.GetFiles(sPath))

{

FileInfo fi = new FileInfo(fName);

ZipEntry entry = new ZipEntry(fi.Name);

FileStream sReader = File.OpenRead(fName);

byte[] buff = new byte[Convert.ToInt32(sReader.Length)];

sReader.Read(buff, 0, (int) sReader.Length);

entry.DateTime = fi.LastWriteTime;

entry.Size = sReader.Length;

sReader.Close();

zipOut.PutNextEntry(entry);

zipOut.Write(buff, 0, buff.Length);

}

zipOut.Finish();

zipOut.Close();

Dont forget to import the fully qualified namespace using ICSharpCode.SharpZipLib.Zip;

Best Regards,

Posted by haissam | 1 comment(s)

When a new window is being opened from a modal or modaless form, it may loses the session. The cause according to Microsoft "This behavior occurs because Internet Explorer windows that are opened from a from a modal or modeless HTML dialog box may not be opened in the same process.".

Walkaround:

Send the parent window of the dialog box into the dialog box then use this object open the new window.

example below

Page1.aspx (Suppose it's the parent widow from which you want to open the dialogbox)

<script language=javascript>

function Open()

{

window.ShowModalDialog('WebForm2.aspx', window)

}

</script>

now in WebForm2.aspx, if you want to open another window you use

dialogArguments.window.open('WebForm3.aspx');

in this way, the WebForm3.aspx will still have the values of the session.

Best Regards,

 

 

Posted by haissam | with no comments

In this blog post, i will provide a code snippet of how to run a process (in this case it is WindowsMediaPlayer.exe) which exists in your application root folder.

// Create An instance of the Process class responsible for starting the newly process.

System.Diagnostics.Process process1 = new System.Diagnostics.Process();

// Set the directory where the file resides

process1.StartInfo.WorkingDirectory = Request.MapPath("~/");

// Set the filename name of the file you want to open

process1.StartInfo.FileName = Request.MapPath("WindowsMediaPlayer.exe"); 

// Start the process

process1.Start();

 

 

Hope this helps,

Posted by haissam | 9 comment(s)
The leading UI suite for ASP.NET - Telerik radControls
Outstanding performance. Full ASP.NET AJAX support. Nearly codeless development.