We are providing online training of realtime Live project on Asp.Net MVC with Angular and Web API. For more information click here. If you have any query then drop the messase in CONTACT FORM

Wednesday, July 22, 2015

Interview qustionns and answers of XML And File IO in C#

1. What is Extensible Markup Language (XML)?
XML is a simple and flexible markup language in the text format. Nowadays, it is widely used to exchange a large variety of data over the Internet. XML consists of data as text in well-defined customized layouts by using self-defining tags. These user-defined tags are user-friendly because they contain the name given by the user and make the information easily understandable to a user. These user-friendly features made XML to be widely used as a standard data-interchange format. The World Wide Web Consortium (W3C) frequently develops new standards for XML usage by different software vendors and solution providers. XML plays a very significant role with respect to .NET Framework 4.0. .NET Framework 4.0 provides us with a namespace called System.Xml, which includes classes that are used to work with XML.

2. What is the version information in XML?
"Version" tag shows which version of XML is used.

3. If XML does not have a closing tag will it work?
No, every tag in XML, which is opened, should have a closing tag.

4. Is XML case sensitive?
Yes, XML is case sensitive.

5. Explain the difference between XML and HTML.
XML describes data while HTML describes how the data should be displayed. Therefore, HTML is about displaying information while XML is about describing information.
XML supports user-defined tags while HTML provides pre-defined tags.
XML is a case-sensitive language while HTML language is not case-sensitive.
In XML, all tags must be closed; while in HTML, it is not necessary to close each tag.

6. What is XML DOM?
The DOM stands for Document Object Model, which describes the logical formation of documents and provides the way to access and manipulate a document. It supplies an Application Programming Interface (API) to XML documents. It is built around the object-oriented design; therefore, it is known as DOM. The DOM model considers an XML document as a composition of objects and every object consists of properties and behaviors that can be manipulated by the DOM methods. The DOM allows creating and building XML documents, navigating the structure of documents, and managing the elements and their data. You can use the DOM methods and objects with any language, such as C#, VB, JavaScript, and VBScript.

7. Which namespaces in .NET are used for XML?
The System.xml.dll is the real physical file, which contains the XML implementation. Some of the other namespaces that allow .NET to use XML are as follows:
System.Xml
System.Xml.Schema
System.Xml.XPath
System.Xml.Xsl

8. Explain different types of XML Application Programming Interface (API).
The following are two main types of XML parsers:
Tree-based API - Compiles an XML document into a tree structure and loads it into memory. You can traverse and change the tree structure. The DOM is an example of a tree-based API.
Event-based API - Provides the report to an application about the parsing events by a set of built-in callback functions. An example of the event-based API is SAX.

9. Explain the XmlReader class.
The XmlReader class is used to read XML data in a fast, forward-only, and non-cached manner.
To work with XmlReader class in .NET, you need to import the following namespace:

In C#:
using System.Xml;

In VB:
Imports System.Xml

10. Describe the XmlWriter class.
The XmlWriter class is used to write XML to a stream, a file, or a Textwriter object. This class works in a forward-only, non-cached manner. You can configure the XmlWriter object up to a large extent. With this object, you can specify a few things, such as whether to indent content or not, the amount to indent, what quote character to use in attribute values, and whether or not namespaces are supported.

11. What is XPath?
XPath stands for XML Path. It is a language used to access different parts of an XML document, such as elements and attributes.

12. What is an XML attribute?
An XML attribute contains additional information regarding that particular element. The XML attributes use the name-value pair. For example, the element student has an attribute called id and the value of this attribute is set to s01, as shown in the following code snippet:

<Student ID="s01">
...
</Student>

13. The XML elements cannot be empty. Is it true?
No, it is not true.

14. Describe the role that XSL can play while dynamically generating HTML pages from a relational database.
The SQLXML 3.0 and advanced versions provide the facility of mapping the SQL queries output with XSLT templates. It uses XSLT to present the records that are retrieved from databases on Web pages (HTML pages).

An application can use XSLT to modify the output that is retrieved from data sources and display the output by XSL templates. The XSLT displays data without affecting the database query and the code of the application.

15. What are the advantages of DOM?
The following are the advantages of DOM:
DOM stores the entire XML document into memory before processing. Therefore, the XML structure can be easily modified and values can be added, changed, and removed.
DOM enables to traverse the XML structure in any direction. It means that you can access any node of the XML structure by traversing through the XML structure.

16. Give an example of a DOM-enabled XML parser.
The XML parser is MSXML, which is fully DOM-enabled.

17. What is an XML schema?
An XML schema provides the definition of an XML document. This implies that an XML schema defines the following in an XML document:
The elements that can appear in an XML document.
The attributes that can appear in an XML document.
The elements that are child elements.
The order of child elements.
The number of child elements.
Whether an element is empty or it includes some text.
The data types for elements and attributes.

18. State the advantages of XML schemas over DTD.
Microsoft developed a language known as the XML Schema Definition (XSD) to describe the schema to an XML document. The following are the advantages of XML schemas over DTDs:
XSD keeps much better control over types of data than the DTD.
DTD does not allow creating customized data types while the XSD provides full support to create customized data types.
XSD allows you to specify restrictions on data. It means that you can define the type of data that should be stored in an element, for example, numbers or alphabets.
The XSD is quite easy to learn and to understand because its syntax is the same as that of the XML document.

19. Using XSLT, how would you extract the value of a specific attribute from an element in an XML document?
The components necessary for the above-mentioned operation are as follows:
The template element - Matches the correct XML element.
The value-of element - Selects the attribute value.
The optional apply-templates element - Allows continuous processing of the document

20. Which classes are supported to make an XML DOM?
The following are the different classes in the System.Xml namespace that make up the XML DOM:
The XmlNode class
The XmlDocument Class
The XmlElement Class
The XmlAttribute Class
The XmlText class
The XmlComment class
The XmlNodeList Class

21. Which class is used to encode and decode XML names and contains different methods to convert between CLR types and XSD types.
The XmlConvert Class.

22. What is DTD?
The DTD is the Document Type Definition that describes the formation of the content of an XML document. The DTD manages the data to store in a consistent format. It defines the XML elements and attributes about how they should be present in XML documents and what relation they should have with other elements and attributes. The DTD also allows you to mention whether an XML element is optional or not. If the XML documents are not according to the DTD rules, they are not considered valid.

23. Is it true that the XML's goal is to replace HTML?
No, it is not true. Both are necessary for their respective fields.

24. What is XSLT?
XSLT is Extensible Stylesheet Language Transformations that is a part of XML, which is a mechanism to transform an XML document into another XML or HTML document.

25. Describe the rules and regulations that must be followed while creating a well-formed XML document.
The following are the rules and regulations that are necessary to follow while creating a well-formed XML document:
Every start tag must end with an end tag.
A root element should be included for enclosing other child elements.
XML tags are case-sensitive; therefore, start and end tags must be of the same spelling and the casing should also be the same.
XML's empty tags are necessary to close with a forward slash (/).
XML's attributes values are necessary to enclose within double quotation marks.
XML tags must be properly nested. It means starting tags should be closed in the reverse order in which they present.

26. What are the naming conventions required for XML elements tags?
The following are the naming conventions that need to be followed for XML elements tags:
Element names should contain only characters, numbers, hyphens, and periods.
Element names cannot begin with a number or punctuation character.
Element names must not start with the word xml (or XML, or Xml).
Element names cannot consist of spaces.
Element names can be used any words except xml, XML, or Xml because no words are reserved in XML.

27. The XML preserves white spaces. Is it true?
Yes, it is true.

28. Explain the XML elements.
The elements are the central units of an XML document that explain and identify data. The elements are represented by the tags. You can also make your own tags, which make XML a user-friendly language. By creating custom meaningful elements, you can improve the readability of the document. XML elements can be nested and the nested elements are known as child elements

29. What are the classes which are used to traverse the XML Document?

  • XmlNode
  • XPathDocument
  • XPathNavigator

30)Universal Resource Identifier (URI)
A Universal Resource Identifier (URI) is a resource name available on the Internet. A URI contains three parts: the naming schema (a protocol used to access the resource), the name of the machine (in the form of an Internet Protocol) upon which the resource resides, and the name of the resource (the file name).

31)what is the prolog section in XML Document?
The prolog part of a document appears before the root tag. The prolog information applies to the entire document. It can have character encoding, stylesheets, comments, and processing instructions. This is an example of a prolog:

<?XML version ="1.0" ?>

<?xml-stylesheet type="text/xsl" href ="books.xsl" ?>

<!DOCTYPEStudentRecord SYSTEM "mydtd.dtd">

<!=my comments - - - ->

32. What is a Well-formed XML document?
A well-formed XML document is a document that conforms to the XML syntax rules, like:
it must begin with the XML declaration
it must have one unique root element
start-tags must have matching end-tags
elements are case sensitive
all elements must be closed
all elements must be properly nested
all attribute values must be quoted
entities must be used for special characters

33. How can XML be used?

  • XML Separates Data from HTML
  • XML Simplifies Data Sharing
  • XML Simplifies Data Transport
  • XML Simplifies Platform Changes
  • XML Makes Your Data More Available
  • XML is Used to Create New Internet Languages

34. Is error allowed in an XML document?
Ans. No, browser compiles at the time of opening an XML file.

35.HowXML Schemas are much more powerful than DTDs?

  • XML Schemas Support Data Types
  • XML Schemas use XML Syntax
  • XML Schemas Secure Data Communication
  • XML Schemas are Extensible

36. What is a Simple Element?
A simple element is an XML element that can contain only text. It cannot contain any other elements or attributes.

However, the "only text" restriction is quite misleading. The text can be of many different types. It can be one of the types included in the XML Schema definition (Boolean, string, date, etc.), or it can be a custom type that you can define yourself.

You can also add restrictions (facets) to a data type in order to limit its content, or you can require the data to match a specific pattern.

The syntax for defining a simple element is:

<xs:element name="xxx" type="yyy"/>

37. What is a Complex Element?

A complex element is an XML element that contains other elements and/or attributes.

There are four kinds of complex elements:
empty elements
elements that contain only other elements
elements that contain only text
elements that contain both other elements and text

38. What is an Attribute?
Simple elements cannot have attributes. If an element has attributes, it is considered to be of a complex type. But the attribute itself is always declared as a simple type.

The syntax for defining an attribute is:

<xs:attribute name="xxx" type="yyy"/>

39. What is the common datatype which is used in XML-Schema?

XML Schema has a lot of built-in data types. The most common types are:

  • xs: string
  • xs: decimal
  • xs: integer
  • xs: boolean
  • xs: date
  • xs: time

40. How to generate an XSD file using Visual Studio?
Add one XML file from the add menu
àafter writing XML documentà
Click on XML menu à Click Create Schema
Visual Studio will automatically generate schema

41. what are the disadvantages of XML

  • Large in size.
  • Sometimes it is not understandable.
  • This is not good for a large amount of data.
  • If it is a large data then finding an error is very difficult.

42. Can you explain why your project needed XML?
Note: - This is an interview question where the interviewer wants to know why you have chosen XML. Remember XML was meant to exchange data between two entities as you can define your user-friendly tags with ease. In real-world scenarios, XML is meant to exchange data. For instance, you have two applications that want to exchange information. But because they work in two complete opposite technologies it’s difficult to do it technically. For instance one application is made in JAVA and the other in .NET. But both languages understand XML so one of the applications will spit XML file which will be consumed and parsed by other applications You can give a scenario of two applications that are working separately and how you chose XML as the data transport medium.

43. Define XPATH?

It is an XML query language to select specific parts of an XML document. Using XPATH you can address or filter elements and text in an XML document. For instance, a simple XPath expression like “Invoice/Amount” states find the “Amount” node which are children of the “Invoice” node.

44. What is the concept of XPointer?
XPointer is used to locate data within the XML document. XPointer can point to a particular portion of an XML document, for instance, address.xml#xpointer(/descendant::streetnumber[@id=9]) So the above XPointer points streetnumber=9 in “address.xml

45. How do I create my own document type?
Ans: - Document types usually need a formal description, either a DTD or a Schema. While it is possible to process well-formed XML documents without any such description, trying to create them without one is asking for trouble. A DTD or Schema is used with an XML editor or API interface to guide and control the construction of the document, making sure the right elements go in the right places.
Creating your own document type, therefore, begins with an analysis of the class of documents you want to describe: reports, invoices, letters, configuration files, credit-card verification requests, or whatever. Once you have the structure correct, you write code to express this formally, using DTD or Schema syntax.

46. What is SOAP and how does it relate to XML?
Ans: - The Simple Object Access Protocol (SOAP) uses XML to define a protocol for the exchange of information in distributed computing environments. SOAP consists of three components: an envelope, a set of encoding rules, and a convention for representing remote procedure calls. Unless experience with SOAP is a direct requirement for the open position, knowing the specifics of the protocol, or how it can be used in conjunction with HTTP, is not as important as identifying it as a natural application of XML

47. Define XMLHttpRequest Object?
Ans:-
Using XMLHttpRequest Object:

  • Updated a web page without reloading.
  • Requesting data from a server after the page has loaded.
  • Receive data from a server after the page has loaded.
  • Send data to a server in the background.

XMLHttpRequest Object creating like:
Xmlhttp=new XMLHttpRequest ();

48. What are basic problems of using Attributes?
And:-
Some of the problems with using attributes are:
1. Attributes cannot contain multiple values
2. Attributes cannot contain tree structures
3. Attributes are not easily expandable
Attributes are difficult to read and maintain. Use elements for data. Use attributes for information that is not relevant to the data.

49. Define essential a component of security does the XML Signatures provide?
Ans:-
Three Components are:
1. Authentication
2. Message integrity and
3. Non-repudiation
In addition to signature information, an XML Signature can also contain information describing the key used to sign the content.

50. what is prolog?
First line of code in xml <?xml version=”1.0”?> is nothing but prolog.

51. What is a markup language?
A markup language is a set of words and symbols for describing the identity of pieces of a document (for example ‘this is a paragraph’, ‘this is a heading’, ‘this is a list’, ‘this is the caption of this figure’, etc). Programs can use this with a stylesheet to create output for screen, print, audio, video, Braille, etc.
Some markup languages (eg those used in word processors) only describe appearances (‘this is italics’, ‘this is bold’), but this method can only be used for display and is not normally re-usable for anything else.

52. What is SGML?
SGML is the Standard Generalized Markup Language (ISO 8879:1986), the international standard for defining descriptions of the structure of different types of electronic documents. SGML is very large, powerful, and complex. It has been in heavy industrial and commercial use for nearly two decades, and there is a significant body of expertise and software to go with it.
XML is a lightweight cut-down version of SGML which keeps enough of its functionality to make it useful but removes all the optional features which made SGML too complex to program for in a Web environment.

53. What is parsing and how do I do it in XML?
Parsing is the act of splitting up information into its component parts (schools used to teach this in language classes until the teaching profession collectively caught the anti-grammar disease).
‘Mary feeds Spot’ parses as
1. Subject = Mary, proper noun, nominative case
2. Verb = feeds, transitive, third person singular, present tense
3. Object = Spot, proper noun, accusative case
In computing, a parser is a program (or a piece of code or API that you can reference inside your own programs) which analyses files to identify the component parts. All applications that read input have a parser of some kind, otherwise, they'd never be able to figure out what the information means. Microsoft Word contains a parser that runs when you open a .doc file and checks that it can identify all the hidden codes. Give it a corrupted file and you'll get an error message.
XML applications are just the same: they contain a parser that reads XML and identifies the function of each the pieces of the document, and it then makes that information available in memory to the rest of the program.
While reading an XML file, a parser checks the syntax (pointy brackets, matching quotes, etc) for well-formedness, and reports any violations (reportable errors). The XML Specification lists what these are.
Validation is another stage beyond parsing. As the component parts of the program are identified, a validating parser can compare them with the pattern laid down by a DTD or a Schema, to check that they conform. In the process, default values and datatypes (if specified) can be added to the in-memory result of the validation that the validating parser gives to the application.

<person corpid="abc123" birth="1960-02-31" gender="female"> <name> <forename>Judy</forename> <surname>O'Grady</surname> </name> </person>
The example above parses as: 1. Element person identified with Attribute corpid containing abc123 and Attribute birth containing 1960-02-31 and Attribute gender containing female containing ...
2. Element name containing ...
3. Element forename containing text ‘Judy’ followed by ...
4. Element surname containing text ‘O'Grady’.

54. What are the special characters in XML
For normal text (not markup), there are no special characters: just make sure your document refers to the correct encoding scheme for the language and/or writing system you want to use, and that your computer correctly stores the file using that encoding scheme. See the question on non-Latin characters for a longer explanation.
If your keyboard will not allow you to type the characters you want, or if you want to use characters outside the limits of the encoding scheme you have chosen, you can use a symbolic notation called ‘entity referencing’. Entity references can either be numeric, using the decimal or hexadecimal Unicode code point for the character (eg if your keyboard has no Euro symbol (€) you can type €); or they can be character, using an established name which you declare in your DTD (eg ) and then use as € in your document. If you are using a Schema, you must use the numeric form for all except the five below because Schemas have no way to make character entity declarations.
If you use XML with no DTD, then these five character entities are assumed to be predeclared, and you can use them without declaring them:
The less-than character (<) starts element markup (the first character of a start-tag or an end-tag).

The ampersand character (&) starts entity markup (the first character of a character entity reference).

The greater-than character (>) ends a start-tag or an end-tag.
The double-quote character (") can be symbolized with this character entity reference when you need to embed a double-quote inside a string that is already double-quoted.
'
The apostrophe or single-quote character (') can be symbolized with this character entity reference when you need to embed a single-quote or apostrophe inside a string that is already single-quoted.
If you are using a DTD then you must declare all the character entities you need to use (if any), including any of the five above that you plan on using (they cease to be predeclared if you use a DTD). If you are using a Schema, you must use the numeric form for all except the five above because Schemas have no way to make character entity declarations.

55. Where can I declare an XML namespace?
You can declare an XML namespace on any element in an XML document. The namespace is in scope for that element and all its descendants unless it is overridden.

56. What is an XML namespace prefix?
An XML namespace prefix is a prefix used to specify that a local element type or attribute name is in a particular XML namespace. For example, in the following, the serv prefix specifies that the Address element type name is in the http://www.google.com/ito/addresses namespace:
<serv:Addresses xmlns:serv="http://www.google.com/ito/addresses">

57. What's XLink?
This specification defines the XML Linking Language (XLink), which allows elements to be inserted into XML documents in order to create and describe links between resources. It uses XML syntax to create structures that can describe links similar to the simple unidirectional hyperlinks of today's HTML, as well as more sophisticated links.
Definition: An XLink link is an explicit relationship between resources or portions of resources.] [Definition: It is made explicit by an XLink linking element, which is an XLink-conforming XML element that asserts the existence of a link.] There are six XLink elements; only two of them are considered linking elements. The others provide various pieces of information that describe the characteristics of a link. (The term "link" as used in this specification refers only to an XLink link, though nothing prevents non-XLink constructs from serving as links.)

58. Which classes are supported to make an XML DOM?
The following are the different classes in the System.Xml namespace that make up the XML DOM:
  • The XmlNode class
  • The XmlDocument Class
  • The XmlElement Class
  • The XmlAttribute Class
  • The XmlText class
  • The XmlComment class
  • The XmlNodeList Class
59. What are the advantages of DOM?
The following are the advantages of DOM:
DOM stores the entire XML document into memory before processing. Therefore, the XML structure can be easily modified and values can be added, changed, and removed.
DOM enables to traverse the XML structure in any direction. It means that you can access any node of the XML structure by traversing through the XML structure.

60. Explain different types of XML Application Programming Interface (API).
The following are two main types of XML parsers:
Tree-based API - Compiles an XML document into a tree structure and loads it into memory. You can traverse and change the tree structure. The DOM is an example of a tree-based API.
Event-based API - Provides the report to an application about the parsing events by a set of built-in callback functions. An example of the event-based API is SAX.

61. What is File Mode?
Answer: The meaning of file mode means in which mode we want to open the file62.

62. Types Of file mode?
Ans: Types of modes are read mode, write mode.

63. What is Pointer?
Ans: A pointer is a variable that holds the address of another variable.

64. Which one is most useful in Structure or Union?
Ans: Union is useful because of memory no wastage but structures are frequently used than unions.

65. What System.IO Name Space
Answer. The classes in the namespace System.IO provide various methods to retrieve
and changes information about Files as well as Directories. In C#, to perform a file I/O
operation, you can use the same familiar basics of creating, opening, closing, reading, and
writing using .NET Framework equivalent classes and methods.

66. How to use C# Directory Class
Answer: Directory class in CSharp exposes methods to create, delete, move, etc. operations to directories and subdirectories. Because of the static nature of the C# Directory class, we do not have to instantiate the class. We can call the methods in the C# Directory class directly from the Directory class itself.

67. How to use C# FileStream Class
Answer: The FileStream Class represents a File in the Computer. Use the FileStream class to read from, write to, open, and close files on a file system, as well as to manipulate other
file related operating system handles including pipes, standard input, and standard output.

FileStream allows moving data to and from the stream as arrays of bytes. We operate
File using FileMode in FileStream Class.

68. How to use C# Textreader Class and TextWriter Class?
Answer: Textreader and TextWriter are another way to read and write file respectively,
even though these do not stream classes. Textreader represents a reader that can read a sequential series of characters. The StreamReader and StreamWriter classes are derived from TextReader and TextWriter classes respectively, which read characters from streams and strings.

69. How to create a directory using Directory class in C#?
In order to create a new directory using Directory class in C#, we can call the CreateDirectory method directly from Directory class.

Syntax : Directory.CreateDirectory(string DirPath)

DirPath: The name of the new directory

CSharp Code : Directory.CreateDirectory("c:\\testDir1");

70. How to check a directory exist or not using Directory class in C#?

Before we create a directory or folder, we usually check that directory or folder exists or not. In C# we are using the Exists method in the Directory class.

Syntax : bool Directory.Exist(string DirPath)

DirPath : The name of the directory

bool: Returns true or false -

if directory exists it Returns true, else it returns false

CSharp Code : Directory.Exists("c:\\testDir1")

71. How to move a Directory using Directory class in C#?
If we want to move a directory and its contents from one location to another, we can use the Move method in the C# Directory class.

Syntax : void Directory.Move(string sourceDirName,string destDirName)

sourceDirName : The source directory we want to move.

destDirName : The destinations directory name.

CSharp Code : Directory.Move("c:\\testDir1\\testDir2", "c:\\testDir");

72. How to delete a Directory using Directory class in C#?
When we want to delete a directory we can use the Delete method in the C# Directory class

Syntax : void Directory.Delete(string DirPath)

DirPath : The Directory we want to delete.

CSharp Code : Directory.Delete("c:\\testDir1");

73. How to create a File using C# File class?
In order to create a new File using C# File class, we can call Create a method in the File class.

Syntax : FileSttream File.Create(string FilePath)

FilePath : The name of the new File Object

CSharp Code : File.Create("c:\\testFile.txt");

74. How to check a File exist or not using C# File class?
Before we create a File object, we usually check that File exists or not. For that, we are using the Exists method in the C# File class.

Syntax : bool File.Exists(string FilePath)

FilePath : The name of the File

bool: Returns true or false -

if File exists it Returns true else Returns false

CSharp Code : File.Exists("c:\\testFile.txt")

75. Name some classes in System.IO name space?
These are some important classes under System.IO namespace

  • File
  • FileInfo
  • Directory
  • DirectoryInfo
  • DriveInfo
  • StreamReader
  • StreamWriter
  • StringReader
  • StringWriter
  • BinaryReader
  • BinaryWriter
  • Path etc.

76. What are advantage and disadvantage using file operation?
The main advantage of files is, they are persistent and they are readily available for the use of the application and the disadvantage is, If the number of users accessing the same file it will degrade the performance of the application.

77. Under which name space file operations can be done?
System.IO name space.

78. Why we use files?
Variables and arrays only provide temporary storage, they lost when a program terminates. But the files are permanent and they are available any time for the application.

79. What is stream in file operations?
Stream is a sequence of bytes traveling from a source to a destination over a communication path.

80. Why Dispose ( ) comes into the picture?
Garbage Collector is responsible for the automatic memory management but the Garbage Collector is under control of CLR. Here file operations are under control of OS so the garbage collector will not come into the picture. To release memory used by the instances in file operation we need to call the Dispose ( ).

81. Which Name Space added in .net4.5 regarding file operations(compression and decompression)?
System.IO.Compression name space. This name Space contains classes that provide basic compression and decompression services for streams.

82. What is the difference between Dispose ( ) & Flush ( )?
Dispose ( ) is used to release all resources used by the current instances where as Flush ( ) is used to clear all buffer for the current stream.

83. What is the use of Seek ( )?
We can seek to a specific location in our file with the Seek () method.

84. How to get the total size of a physical drive on your computer?
By using TotalSize property of DriveInfo class in System.IO name space.

85.What is the difference between ReadDecimal ( ) and ReadInt32 ( )?
ReadDecimal ( ) is used to read a decimal value from the current stream where as ReadInt32 ( ) is used to read an integer value from the currentstream.

86. What is the use of a BinaryWriter & BinaryReader class?
BinaryWriter class is responsible for writing primitive data types in binary to a stream and BinaryReader class is responsible for reading primitive data types as a binary value.

87. How to get the file names present in a drive using directory class?
Directory.GetFiles(String)->Returns an array(upto .net3.5)
Directory.EnumerateFiles(String)->Returns an enumerable
collection(Newly added in .net4.0).

88. How to check whether the directory and file exist or not?
Directory.Exists(path)
File.Exists(path)

89.What is the difference between Peek ( ) & Seek ( )?
Peek ( ) is used to Returns the next available character but does not consume it whereas Seek ( ) is used to set the position within the current stream.

90. What are the different types of files?
There are 2 kinds of files. They are Text files & Binary files etc

91. How to create a Zip file?
By using ZipClass present under the System.IO.Compression name space.

Ex: using System;

class Program
{
static void Main(string[] args)
{

string startPath = @"c:\example\start";

string zipPath = @"c:\example\result.zip";

string extractPath = @"c:\example\extract";

ZipFile.CreateFromDirectory(startPath, zipPath);

ZipFile.ExtractToDirectory(zipPath, extractPath);

}

}

92. Why we use the Close ( ) method?
By using Close ( ) we can close the current class object and underlying stream.

93. What type of data ZipStream Compress?
Any data less than 4gb in size

94. How we can deal with the audio and video files?
By using Audio and video class. We create the instances of these Classes and provide (path) as the argument. In Windows applications with the help of MediaElement control, we deal with audio and video files.

95.how we will get the creation time of a file?
By using the method GetCreationTime of file class.

Ex:DateTime CreatedDate=File.GetCreationTime(@"C:\Example\MyTest.txt");

Console.WriteLine("file created: " + fileCreatedDate);

96. How to get the last access time of a file?
By using GetLastAccessTime method of file class.

Ex:DateTime dt = File.GetLastAccessTime(path);

Console.WriteLine("The last access time for this file was {0}.", dt);

97. Which methods directory and directoryInfo classes have?

  • Directory class: Static methods
  • DirectoryInfo: Instance methods and is a sealed class.

98.In directory and directory info class to get directories and files information which methods we have up to .net3.5?
Get Directories for directories information and get files for files information. These will gives the result in an array format.

99.In directory and directory info class to get directories and files information which methods are introduced in .net4.0?
Enumerate Directories for directories information and enumerate files for files information. These will give the result in Enumerable collection, this will give better performance than getting Directories and Get Files methods.

100. Why didn’t I have to use the Close () method to close the file after I used File. ReadAllText () and File.WriteAllText ()?
A: The File class has several very useful static methods that automatically open up a file, read or write data, and then close it automatically. In addition to the ReadAllText () and WriteAllText () methods, there are ReadAllBytes () and WriteAllBytes (), which work with bytearrays, and ReadAllLines () and WriteAllLines (), which read and write string arrays, where each string in the array is a separate line in the file. All of these methods automatically open and close the streams, so you can do your whole file operation in a single statement.

101. How can you change an object into a remote object?
Any object can be changed into a remote object by deriving it

From MarshalByRefObject Class.

102. What is considered a remote object?
Any object outside the application domain of the calling application is considered a remote object, even if the objects are executing on the same machine.

103. Which is faster, interacting with a database or using a file system for input-output?
If you use a database, there is an overhead for transactions, security, and Index management, etc. on the one hand. On the other hand, you can get caching (which could significantly speed up your application) and better performance for random access, if you have a lot of data. In a multithreaded environment, I suggest using a database because of a property implemented locking mechanism. If you have indexes on your table correctly then I think it would be better to use a database instead of the file system to get better performance. Also to include that if your data in the database is going to be millions of records then also the performance will not be affected when compared to the file system with that much amount of data

104. when FileLoadException occurs?
The exception that is thrown when a path or file name is longer than the system-defined maximum length.

105.what is the purpose of ReadAllLines( ) method?
The "ReadAllLines" method reads all the contents of a file and stores each line at a new index in an array of string type.

106.what is the purpose of ReadAllBytes( ) method?

The "ReadAllBytes" method reads the contents of a file as binary data and stores the data in a byte array.

string filePath = @"C:\MyData\TestFile.txt";
byte[] testDataRawBytes = File.ReadAllBytes(filePath);


No comments: