Try
Dim stream As FileStream = File.Open("d:\word.doc", FileMode.Open) 'replace the location with your word doc.
stream.Position = 0
' Now read s into a byte buffer.
Dim bytes() As Byte = New Byte(stream.Length) {}
Dim numBytesToRead As Integer = CType(stream.Length, Integer)
Dim numBytesRead As Integer = 0
While numBytesToRead > 0
' Read may return anything from 0 to numBytesToRead.
Dim n As Integer = stream.Read(bytes, numBytesRead, numBytesToRead)
' The end of the file is reached.
If n = 0 Then
Exit While
End If
numBytesRead += n
numBytesToRead -= n
End While
stream.Close()
Response.Clear()
Response.ContentType = "application/word"
Response.AddHeader("Content-disposition", "filename=output.doc")
Response.OutputStream.Write(bytes, 0, bytes.Length)
Response.OutputStream.Flush()
Response.OutputStream.Close()
Response.Flush()
Response.Close()
Catch ex As Exception
Throw ex
End Try
Monday, February 2, 2009
Open MS Word document using ASP.NET
Saturday, December 13, 2008
Retrive all columns in the DB
To Retrive Full columns in a DB
======================
select distinct
TBL.name as TableName,
COL.Name as ColumnName, TYP.name as Type, COL.max_length as Length,
COL.precision as Precision, CASE COL.is_nullable WHEN 1 THEN 'Null' ELSE 'Not Null' end as 'Null' from sys.columns COL
inner join sys.objects TBL on COL.object_id= TBL.object_id
inner join sys.types TYP on TYP.system_type_id= COL.system_type_id
where TBL.type ='u' and TBL.name != 'sysdiagrams'
and TYP.name !='sysname' order by
TBL.name,
COL.name
DataTable Load()
DataTable's Load method.
===================
string sql = "Select * from MyTable";
SqlCommand cmd = new SqlCommand(sql, MyConnection);
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
//Load the SqlDataReader object to the DataTable object as follows.
dt.Load(dr);
Response.Write(dt.Rows.Count.ToString());
Merge DataSet
DataSet.Merge(ds)
==============
For the merge to take place between the datasets, apart from the data type and column name, the table name should also be the same.
Dim myConnection as New SqlConnection (strConn)
Dim DS1 As DataSet
Dim DS1 As DataSet
Dim MyCommand As SqlDataAdapter
MyCommand = new SqlDataAdapter("exec s_get_table1", MyConnection)
DS1 = new DataSet()
MyCommand.Fill(DS1, "MyTable")
MyCommand = new SqlDataAdapter("exec s_get_table2", MyConnection)
DS2 = new DataSet()
MyCommand.Fill(DS2, "MyTable")
'Now the code works because the table name for both datasets are the same.
'Also the data type and column name for both tables are the same.
ds1.merge(ds2)
MyDataGrid.DataSource=DS1.tables(0).DefaultView
MyDataGrid.DataBind()
Globalization - Display currency
using System;
using System.Globalization;
public class TestClass
{
public static void Main()
{
int i = 100;
// Creates a CultureInfo for English in Belize.
CultureInfo bz = new CultureInfo("en-BZ");
// Displays i formatted as currency for the bz.
Console.WriteLine(i.ToString("c", bz));
// Creates a CultureInfo for English in the U.S.
CultureInfo us = new CultureInfo("en-US");
// Display i formatted as currency for us.
Console.WriteLine(i.ToString("c", us));
// Creates a CultureInfo for Danish in Denmark.
CultureInfo dk = new CultureInfo("da-DK");
// Displays i formatted as currency for dk.
Console.WriteLine(i.ToString("c", dk));
}
}
Saturday, August 30, 2008
Wednesday, July 30, 2008
c# String functions Part1
// Create a Unicode String with 5 Greek Alpha characters
String szGreekAlpha = new String('\u0319',5);
// Create a Unicode String with a Greek Omega character
String szGreekOmega = new String(new char [] {'\u03A9','\u03A9','\u03A9'},2,1);
String szGreekLetters = String.Concat(szGreekOmega, szGreekAlpha, szGreekOmega.Clone());
// Examine the result
Console.WriteLine(szGreekLetters);
// The first index of Alpha
int ialpha = szGreekLetters.IndexOf('\u0319');
// The last index of Omega
int iomega = szGreekLetters.LastIndexOf('\u03A9');
Console.WriteLine("The Greek letter Alpha first appears at index " + ialpha +
" and Omega last appears at index " + iomega + " in this String.");
Subscribe to:
Posts (Atom)