Monday, May 12, 2008

Merging Word Docs using ASP.NET,C#

Guys if you wana merge word documents thn you can get the code from here

http://www.codeproject.com/KB/office/mswmergecs.aspx

and you will need to download few dll's that you can get from here

http://www.microsoft.com/downloads/details.aspx?familyid=3c9a983a-ac14-4125-8ba0-d36d67e0f4ad&displaylang=en

if you need the working code let me know

cheers
Ric

Friday, May 2, 2008

USING GDI TO DYNAMICALLY ADD IMAGE OR TEXT ON IMAGE ASP.NET

Using GDI to dynamically add image or text on another image in asp.net/vb.net

Public Function writeimage()

' 'USING GDI TO DYNAMICALLY ADD TEXT AND IMAGES ON IMAGE
' INCULDE THE FOLLOWING :
' Imports System.Drawing
'Imports System.Drawing.Image
'Imports System.Drawing.Drawing2D
'Imports System.Drawing.Imaging

Dim myBitmap As New Bitmap(Server.MapPath(ViewState("Imagepath").ToString))
Dim myGraphic As Graphics = Graphics.FromImage(myBitmap)

'set the smoothing mode
myGraphic.SmoothingMode = SmoothingMode.AntiAlias

'draw the oval
'myGraphic.DrawArc(New Pen(Color.White, 2), 280, 0, 120, 50, 0, 360)

'draw the text
'Session("Text") = AddText.Text

Dim ds As New DataSet
ds = getdata()
Dim i, j As Integer
j = ds.Tables(0).Rows.Count

Dim drow As DataRow
If ds.Tables(0).Rows.Count > 0 Then
For Each drow In ds.Tables(0).Rows
Dim textcheck As String = drow("Text").ToString
Dim imagecheck = drow("imagename").ToString

If textcheck <> "NA" Then
'adding text to the image
myGraphic.DrawString(drow("Text"), New Font("Helvetica", 20, FontStyle.Bold), SystemBrushes.WindowText, New PointF(drow("PosX"), drow("PosY")))

ElseIf imagecheck <> "NA" Then
'adding image to the image
Session("imagepath1") = "Uploadedimages/" & LTrim(drow("imagename"))
Dim myimage1 As New Bitmap(Server.MapPath(Session("Imagepath1").ToString))
Dim myThumbNail As New Bitmap(myimage1, 60, 60) 'this will craete a thumbnail of the image
myGraphic.DrawImage(myThumbNail, New PointF(drow("PosX"), drow("PosY")))
' myGraphic.DrawImage(
End If
Next

End If



'note: enable these 3 lines and disable the previous if you want to see vertical text in action
'Dim stringFormat As New StringFormat()
'stringFormat.FormatFlags = StringFormatFlags.DirectionVertical
'myGraphic.DrawString("Alima!", New Font("Helvetica", 30, FontStyle.Bold), SystemBrushes.WindowText, New PointF(290, 10), stringFormat)

'set the content type
'======Getting Error=========================
'Response.ContentType = "image/jpg"
'============================

'save to the outputstream
Dim myBitmap1 As New Bitmap(myBitmap)

myBitmap1.Save(Server.MapPath("DemoImages/" & Session.SessionID & ".jpg"))
myGraphic.Dispose()
myBitmap.Dispose()
Dim testpath As String = "Demoimages/" & Session.SessionID & ".jpg"
Session("testpath") = testpath
prodimg.ImageUrl = testpath
BindGrid()
AddText.Visible = True

GridView1.Visible = True
Panel1.Visible = False


End Function

Thursday, May 1, 2008

USING LINQ TO SQL CLASSES ASP.NET 2008

'USING linq TO SQL TO iNSERT AND bIND GRID ASP.NET 2008


' Ist of all add Linq to sql classes by right click on project and add new item
' Then from server explorer Drag and drop the Database you want to use on the dbml

file u ' added

'then create and object of tht class and use the code below to add and bind gridview

check code below:

Dim db As New DataClassesDataContext '

Dim insemp As New emp
insemp.EName = TextBox1.Text
insemp.Salary = Convert.ToInt32(TextBox2.Text)
db.emps.InsertOnSubmit(insemp)
db.SubmitChanges()

Dim q = From c In db.emps Select c.EName, c.Salary Where Salary >= 1000

GridView2.DataSource = q
GridView2.DataBind()