Search This Blog
Tuesday, September 17, 2013
Monday, September 16, 2013
CREATING CAB FILES IN .NET
Imports System
Imports System.IO
Imports System.Text
Imports Microsoft.Deployment.Compression.Cab
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\Newfolder\MyTest.txt"
' Delete the file if it exists.
If File.Exists(path) Then
File.Delete(path)
End If
'Create the file.
Dim fs As FileStream = File.Create(path)
AddText(fs, "This is some text")
AddText(fs, "This is some more text,")
AddText(fs, Environment.NewLine & "and this is on a new line")
AddText(fs, Environment.NewLine & Environment.NewLine)
AddText(fs, "The following is a subset of characters:" & Environment.NewLine)
Dim i As Integer
For i = 1 To 120
AddText(fs, Convert.ToChar(i).ToString())
Next
fs.Close()
Dim __cab As CabInfo
Dim list As New List(Of String)
list.Add("c:\Newfolder\MyTest.txt")
__cab = New CabInfo("c:\Newfolder\cab1.cab")
__cab.PackFiles(Nothing, list, Nothing)
''Open the stream and read it back.
'fs = File.OpenRead(path)
'Dim b(1024) As Byte
'Dim temp As UTF8Encoding = New UTF8Encoding(True)
'Do While fs.Read(b, 0, b.Length) > 0
' Console.WriteLine(temp.GetString(b))
'Loop
'fs.Close()
End Sub
Private Shared Sub AddText(ByVal fs As FileStream, ByVal value As String)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)
fs.Write(info, 0, info.Length)
End Sub
End Class
Imports System.IO
Imports System.Text
Imports Microsoft.Deployment.Compression.Cab
Public Class Test
Public Shared Sub Main()
Dim path As String = "c:\Newfolder\MyTest.txt"
' Delete the file if it exists.
If File.Exists(path) Then
File.Delete(path)
End If
'Create the file.
Dim fs As FileStream = File.Create(path)
AddText(fs, "This is some text")
AddText(fs, "This is some more text,")
AddText(fs, Environment.NewLine & "and this is on a new line")
AddText(fs, Environment.NewLine & Environment.NewLine)
AddText(fs, "The following is a subset of characters:" & Environment.NewLine)
Dim i As Integer
For i = 1 To 120
AddText(fs, Convert.ToChar(i).ToString())
Next
fs.Close()
Dim __cab As CabInfo
Dim list As New List(Of String)
list.Add("c:\Newfolder\MyTest.txt")
__cab = New CabInfo("c:\Newfolder\cab1.cab")
__cab.PackFiles(Nothing, list, Nothing)
''Open the stream and read it back.
'fs = File.OpenRead(path)
'Dim b(1024) As Byte
'Dim temp As UTF8Encoding = New UTF8Encoding(True)
'Do While fs.Read(b, 0, b.Length) > 0
' Console.WriteLine(temp.GetString(b))
'Loop
'fs.Close()
End Sub
Private Shared Sub AddText(ByVal fs As FileStream, ByVal value As String)
Dim info As Byte() = New UTF8Encoding(True).GetBytes(value)
fs.Write(info, 0, info.Length)
End Sub
End Class
Monday, February 18, 2013
Dynamically Change CSS on Button Click in ASP.NET
This article will explain on how css can be changed dynamically on button click in asp.net
Introduction
In this article, button is being used to change the CSS using the Button Click event.
There are lots of time we want to change the background dynamically and also the look and feel of the website and you regret using Themes because it only works for asp.net controls and not to HTML Controls.Hence we can use CSS. For simplicity asp.net controls are used in this article,however HTML controls can be used as well.
Objective
Using the code
To work around we have to implement a default look and feel,hence for that i have kept the background color to aqua.so when the page will load for the first time it will have the look and feel of the default css and on button clicks it will change the css and apply the changes as per css rule.
Now to change the CSS dynamically on button click we will use the command argument value given to the button in HTML mark up.
The command argument is the name of the css with extension of the css as well.
In all the css i have a common class .label so that i can also change the look and the feel of the label as well as per the changing the css.
For this i have assigned .label class to the label control.
Make a note that the default.css should have the .label class so that you can apply the changes to the label.
************Using the code and understanding the code*************************
id="lnkCSS" href="css/Default.css" runat="server" rel="stylesheet" type="text/css" />
The above line if you check i have set the runat = server mode to the link so that i can get this link on code behind to change its properties on code behind.
Block of code should be set style as "Code" like below.
// HTML Mark Up
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Dymaic Change of Css.aspx.cs" Inherits="Dymaic_Change_of_Css" %> xmlns="http://www.w3.org/1999/xhtml"> runat="server">id="lnkCSS" href="css/Default.css" runat="server" rel="stylesheet" type="text/css" />
//Default.css
body { background-color:Aqua; font-family:@Adobe Gothic Std B; font-size:15pt; } .label{ font-weight:bold; color:Red; }
//Brown.css
body { background-color:Maroon; font-family:@GulimChe; } .label{ font-weight:bold; color:Yellow; font-size:20pt; }
Yellow.css
body { background-color:Yellow; font-family:Adobe Caslon Pro Bold; } .label{ color:Maroon; font-size:15pt; }
//Code behind
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class Dymaic_Change_of_Css : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnCss1_Click(object sender, EventArgs e) { lnkCSS.Attributes["href"] = "~/css/" + (sender as Button).CommandArgument; // this will change the css as per the command agruement given in the HTML mark up } protected void btnCss2_Click(object sender, EventArgs e) { lnkCSS.Attributes["href"] = "~/css/" + (sender as Button).CommandArgument;// this will change the css as per the command agruement given in the HTML mark up } }
Subscribe to:
Posts (Atom)