:: Home     :: MS Dynamics CRM     :: .Net 1.1     :: .Net 2.0     :: Sharepoint Portal     :: Ajax

  login:        
  passwords:  
 

Asp.Net Interview Questions
Asp.Net 2.0/3.5 Sample Interview Questions and Answers. Interview Tips for a successful job Interview


 

Code Walkthroughs

Datagrid Formatting the Data
We are able to format the content of the datagrid cell by one of two simple methods, dependant upon whether the column is a bound column or whether it is a template column. In our example we shall format the column to have to digits after the decimal point , followed by a...

Datagrid Highlight a Row With Click Through
It is relatively easy to add alternating colours to the rows in your datagrid. However, when we move the mouse over the rows we may want to highlight this row, and possibly to add the option of a click through based on the row selected...

Add a Delete Button to a Datagrid
To add a delete button to a datagrid follows a similar process to adding an edit button. In the datagrid header...

Add an Edit Button to a Datagrid
The datagrid has a predefined editColumn for handling the editing of a datagrid. Adding this simple column definition to a datagrid adds a powerful feature. When a row is not in edit mode the column item shows the word...

Making a Datagrid Row Editable
Two of the most popular methods of editing a datagrid in asp.net are to either select the row and take the user off to a different presentation of the data, or to change the formatting of the row presented in the database with appropriate edit text boxes, checkboxes and...

Adding Tooltips to Datagrid Rows
Adding tooltips to datagrid rows is easy, assuming that you have already created the code for adding row highlighting. In this article I shall assume that you have already read the article entitled Datagrid Highlight a Row With Click Through...

Binding a Datagrid to an Access Database
This list covers the full lifecycle of a content management system, from initially creating the content, through to delivering it to end users...

Adding Data to a DropDownList
The aim of this article is to answer the question 'How do I add items to a DropDownList?' Initially as part of the declaration for the DropDownList we can also define a number of items, much in the same way as in classic ASP...

Getting Current Date Time
In classic ASP we had now() which would return the current date and time. For asp.net this no longer exists. So what should we use...

Test if File Exists
Sometimes, in order to reduce our chance of error, when working with the filesystem in ASP.NET, we need to determine wether a file exists before performing an action on it. The following short piece of code will enable us to test whether a file exists...

Using Javascript with ASP.NET Form Elements
Adding simple pieces of Javascript to an Asp.net page can be acheived by adding to the attributes of the particular imagebutton or linkbutton. if its normal ASP.Net Button then you can...

Regular Expressions
In the table below we list the characters used in .Net regular expressions, together with their meaning, But first...

Authentication in Asp.net
Forms authentication in ASP.Net is far more easier and safe than Asp 3. It is possible to place a web.config file in any directory of a web site.Therefore, we are able to make most of a web site public, whilst providing authentication on, say, one directory...

Discussion Forums

General ASP.NET

.Net Programming

cSharp Home

Sql Server Home

Javascript / Client Side Development

IT Jobs

Ajax Programming

Ruby on Rails Development

Perl Programming

C Programming Language

C++ Programming

Python Programming Language

Laptop Suggestions?

TCL Scripting

Fortran Programming

Scheme Programming

19. GDI+

FAQ Home
   19.1 Why do I get the error message "CS0122: 'System.Drawing.Imaging.ImageFormat.jpeg' is inaccessible due to its protection level "?
   19.2 Why do I get the error message "A generic error occurred in GDI+."?
   19.3 How to draw strings vertically on a Bitmap?
   19.4 I am using GDI+ to write on a bitmap. I know how to make font Italic/Bold. What should be done to apply both Italic and Bold?
   19.5 How can I display image from a Sql Server database?
   19.6 How to display image on a browser without using the image tag?
   19.7 How to rotate a image in ASP.NET?
   19.8 How to show the graphics that have text written on it crisp and clear?
   19.9 I get error "Value of String cannot be converted System.Drawing.Color' when I use label1.BackColor= "Red"?
   19.10 How to load a image from a website URL?
   19.11 How can I check the image raw format i.e how can I find if Image.RawFormat property returns a "jpeg" or "gif",?
   19.12 How to align the text on a bitmap?

19.1 Why do I get the error message "CS0122: 'System.Drawing.Imaging.ImageFormat.jpeg' is inaccessible due to its protection level "?


Try giving the proper file path for the image. Also make sure you have proper permissions on that file.


19.2 Why do I get the error message "A generic error occurred in GDI+."?


Give the proper path of the file. Check your permissions on the server where you are trying to write/read the files


19.3 How to draw strings vertically on a Bitmap?



...
dim sFormat As New StringFormat()
sFormat.FormatFlags = StringFormatFlags.DirectionVertical
...
g.DrawString("Syncfusion", new Font("Arial",16,FontStyle.Italic or FontStyle.Bold ),SystemBrushes.WindowText, new PointF(2,2) , sFormat )



...
StringFormat sFormat = new StringFormat() ;
sFormat.FormatFlags = StringFormatFlags.DirectionVertical ;
...
g.DrawString("Syncfusion", new Font("Arial",16,FontStyle.Italic|FontStyle.Bold ),SystemBrushes.WindowText, new PointF(2,2) ,sFormat) ;
...



19.4 I am using GDI+ to write on a bitmap. I know how to make font Italic/Bold. What should be done to apply both Italic and Bold?


VB.NET


dim fntFont as Font = new Font("Arial",16,FontStyle.Italic|FontStyle.Bold )


C#


Font fntFont =new Font("Arial",16,FontStyle.Italic|FontStyle.Bold ) ;


For more details refer FontStyle Enumeration


19.5 How can I display image from a Sql Server database?


VB.NET


'Function
Public Function showImage(empid As Int32) As Byte()
DimmyconnectionAsNewSqlConnection("Server=localhost;uid=sa;password=;database=northwind;")
Dim mycommand As New SqlCommand("Select Employeeid, FirstName,Photo from Employees where employeeid =" + empid.ToString(), myconnection)
myconnection.Open()
Dim dr As SqlDataReader = mycommand.ExecuteReader()
dr.Read()
Dim imgbyte As Byte() = CType(dr("Photo"), Byte())
Return imgbyte
End Function 'showImage

'In Page_Load
Dim data As Byte() = showImage(2)
Dim offset As Int32 = 78
Dim mstream As New System.IO.MemoryStream()
mstream.Write(data,offset,data.Length -offset)
Dim bmp As New System.Drawing.Bitmap(mstream)
bmp.Save(Server.MapPath("sample.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg)
mstream.Close()
Image1.ImageUrl = Server.MapPath("sample.jpeg")


C#


//Function
public byte [] showImage(Int32 empid)
{
     SqlConnectionmyconnection=newSqlConnection("Server=localhost;uid=sa;password=;database=northwind;");
     SqlCommand mycommand = new SqlCommand ("Select Employeeid, FirstName,Photo from Employees where employeeid =" + empid, myconnection);
     myconnection.Open ();
     SqlDataReader dr= mycommand.ExecuteReader();
     dr.Read();
     byte[] imgbyte =(byte[]) dr["Photo"];
     return imgbyte;
          
}
//In Page_Load
byte[] data = showImage (2);
Int32 offset =78;
System.IO.MemoryStream mstream = new System.IO.MemoryStream ();
mstream.Write(data, offset, data.Length - offset);
System.Drawing.Bitmap bmp= new System.Drawing.Bitmap(mstream);
bmp.Save(Server.MapPath ("sample.jpeg"), System.Drawing.Imaging.ImageFormat.Jpeg );
mstream.Close();
Image1.ImageUrl = Server.MapPath("sample.jpeg");



19.6 How to display image on a browser without using the image tag?


VB.NET


Dim objBitmap As New Bitmap(500, 500)
Dim objGraphics As Graphics = Graphics.FromImage(objBitmap)
objGraphics.Clear(Color.White)
objGraphics.FillRectangle(New SolidBrush(Color.Purple), 0, 0, 400, 10)
objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg)


C#


Bitmap objBitmap = new Bitmap(500, 500);
Graphics objGraphics = Graphics.FromImage(objBitmap);
objGraphics.Clear(Color.White);
objGraphics.FillRectangle(new SolidBrush(Color.Purple ), 0, 0, 400, 10);
objBitmap.Save(Response.OutputStream, ImageFormat.Jpeg);



19.7 How to rotate a image in ASP.NET?


VB.NET


Dim img As System.Drawing.Image
Dim strFilename As String = Server.MapPath("curves1.jpg")
img = System.Drawing.Image.FromFile(strFilename)
Dim b = New System.Drawing.Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb)
Dim g As Graphics = Graphics.FromImage(b)
img.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipXY)
g.DrawImage(img, New Point(0, 0))
Response.ContentType = "image/jpeg"
b.Save(Response.OutputStream, ImageFormat.Jpeg)


C#


System.Drawing.Image img ;
string strFilename = Server.MapPath("curves1.jpg") ;
img = System.Drawing.Image.FromFile(strFilename) ;
Bitmap b = new System.Drawing.Bitmap(img.Width, img.Height, PixelFormat.Format24bppRgb) ;
Graphics g = Graphics.FromImage(b) ;
img.RotateFlip(System.Drawing.RotateFlipType.Rotate270FlipXY) ;
g.DrawImage(img,new Point(0,0)) ;
Response.ContentType="image/jpeg" ;
b.Save(Response.OutputStream, ImageFormat.Jpeg) ;



19.8 How to show the graphics that have text written on it crisp and clear?


Try
VB.NET


objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias


C#


objGraphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;



19.9 I get error "Value of String cannot be converted System.Drawing.Color' when I use label1.BackColor= "Red"?


Try
VB.NET


Label1.BackColor = System.Drawing.Color.FromName("Green")


C#


Label1.BackColor = System.Drawing.Color.FromName("Green");



19.10 How to load a image from a website URL?


Use WebClient to request it and save it to disk, open the local copy.


19.11 How can I check the image raw format i.e how can I find if Image.RawFormat property returns a "jpeg" or "gif",?


VB.NET


if (Img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg)) then
     Response.ContentType = "image/jpeg"
Else
..
End if


C#


if (Img.RawFormat.Equals(System.Drawing.Imaging.ImageFormat.Jpeg))
{
     Response.ContentType = "image/jpeg"
}
else
{
..
}



19.12 How to align the text on a bitmap?


VB.NET


...
Dim sFormat As New StringFormat()
sFormat.Alignment = StringAlignment.Far
...
g.DrawString("Syncfusion", New Font("Arial", 16, FontStyle.Italic), SystemBrushes.WindowText, New PointF(2, 2), sFormat)
......


C#


...
StringFormat sFormat = new StringFormat() ;
sFormat.Alignment = StringAlignment.Far;
...
g.DrawString("Syncfusion", new Font("Arial", 16, FontStyle.Italic), SystemBrushes.WindowText, new PointF(2, 2), sFormat) ;
......
 
Copyright 2005-2015, Megasolutions Ltd  |   Privacy Policy