Get IO, File Stream, Serialization, etc. Related Examples with code from here.
Jayesh Sorathia
You can process the content of an Atom 1.0 or RSS 2.0 feed to extract or get details of the feed. .Net framework provide classes to parse the feed data. We are using System.ServiceModel.Syndication.SyndicationFeedFormatter and System.ServiceModel.Syndication.SyndicationFeed classes.
Read More...
Binary Deserialization is a reverse process of Binary Serialization. In Binary Deserialization we fetch binary file that generated from Binary Serialization and get back orignal object.
Read More...
There is a need to serialize object and store into a file, and then deserialize when required. For Binary Serialization we are using "BinaryFormatter" class which is available in "System.Runtime.Serialization.Formatters.Binary" namespace.
Read More...
You can retrieve stored file from SQL Server Database Table and store as physical file in hard drive.Here is example for this. In this example we retrieved stored file from database record and store as physical file in hard drive.
Read More...
In XML Deserialization you convert XML file data back in to custom class objects. This is a reverse process of XML Serialization. In previous example we serialize on object data in to XML now we take this Generated XML file and create class object from that.
Read More...
There is a need where you want objects data into XML format. You can achieve this using XML Serialization. Using XML Serialization you can convert custom objects data into XML and XML into custom objects. We are using "XmlSerializer" class available in "System.Xml.Serialization" namespace.
Read More...
There is a need in application to upload a file and store into SQL Server Database table. You can do this very simple way. File is stored in sql server as binary data. You need to set "varbinary" data type of the column in which you want to store file. You need to take "varbinary(MAX)" data type.
Read More...
You can get list of all files in particular directory or folder and it's all sub directories. .NET Framework 4 allow to enumerate directories and files using methods that returns enumerable collections. There is a also a methods of get enumerable collections for DirectoryInfo , FileSystemInfo and FileInfo objects.
Read More...
.NET Framework 4 introduce new "CopyTo" method of Stream Class of System.IO namespace. Using this method we can copy one stream to another stream of different stream class. You can also say that write content or data of one stream to another stream.
Read More...
Hash code of a file is useful for check that file contents is changed over the time or not. First time you calculate hash code of a file and store , after some time period you again calculate hash code of a file and compare with stored hash code, If hash code is changed that means contents of the file is changed.
Read More...
You can open a file in read mode and get FileStream Object for reading a stream. After getting FileStream object you can read data using "Read" and "ReadByte" methods. You can open any file ie Text , Image , doc etc.. After reading the file you need to close the FileStream Object.
Read More...
You can read file byte data using "Read" Method of FileStream class and get bytes array. You can also say that read bytes array from FileStream object or read bytes array from FILE. Here are example of this.
Read More...
There is a very quick way in .Net to read the entire file and return a string of data. We are using ReadAllText method of File class. Here are sample example of this. In this example we read the whole file in one statement and return it's string of data. These examples are in both C# and VB.Net .
Read More...
There is a very quick way to open text file and appends data into that file. There are two methods to appends text files AppendAllText and AppendAllLines. These methods open a file. Appends data to the files , and then close the file. If file does not exist, These methods create the files , appends the data and close the file.
Read More...
.Net framework provide the System.IO.Compression.GZipStream or System.IO.Compression.DeflateStream to compress or decompress data. Both GZipStream and DeflateStream classes allow you to use GZIP and Deflate compression algorithms to compress or decompress data.
Read More...
You can also query the text file using LINQ . Here are example for this. In this example we can get specific lines which has matching word given by us. After the LINQ query is executed you need to close file otherwise it gives error on next attempt to access of file.
Read More...
You are able to get stream reader of a file and work on stream reader. After getting Stream Reader and completing work on stream reader you have to close SteramReader using Close method. to avoid any file open errors. Here are example for this.
Read More...
You can get the FileStream of a file by opening a file using File Class. After get FileStream and completing work on file stream you have to close FileSteram using Close method. to avoid any file open errors. Here are example for this.
Read More...
You are able to upload a file on FTP server from your application. Using FtpWebRequest and FtpWebResponse classes executing File Transfer Protocol (FTP) commands from your Web page easy. In this example we are using System.Net and System.IO namespaces. Here is exmple for how to upload file on FTP server.
Read More...
You are able to download file from FTP server and save to your desire location using .Net Using FtpWebRequest and FtpWebResponse classes executing File Transfer Protocol (FTP) commands from your Web page easy. Using these classes, implementing an entire FTP client right from your Web application is now possible. In this example we are using System.Net and System.IO namespaces.
Read More...
There are situations where you want to post data to remote server and other external URL. We can do this using System.Net namespace. In this sample example we have this "http://www.dummydomain.com/pagename.aspx" URL and we want to post query string data like "pageid=1&search=.net" and capture response of this in our code. We are using HttpWebRequest and HttpWebResponse class for this.
Read More...
Screen scrapping means to get other sites data from given URL. You can do this using the HttpWebRequest and HttpWebResponse classes to screen scrape, you can use the following code to build a Web page that will serve as a simple Web browser. You also learn how to display another Web page inside of yours using an HttpWebRequest.
Read More...
.NET Framework includes the System.IO.MemoryMappedFiles namespace, which includes a number of classes that allow you to create memory-mapped files. Memory-mapped files can be useful when you encounter the limitations of the stream objects.
Read More...
Main parts of I/O in the .NET Framework are Reader and Writer classes. These classes help the reading and writing of individual bytes to and from Streams. The .NET Framework provides a wide variety of reader and writer classes, each designed for reading or writing according to a specific set of rules.
Read More...
Now use the BinaryReader and BinaryWriter classes to read and write primitive types to a file.The BinaryWriter writes primitive objects in their native format, so in order to read them using the BinaryReader, you must select the appropriate Read method.
Read More...
StreamReader and StreamWriter classes to write a string to a text file and then read the contents of that text file. Here are Exmaple for Write and Read File.
Read More...
There is a situation where you want to write data in Memory Stream. You can write to the stream by encoding a string containing the information you want to write to a byte array and then using the stream’s Write method to write the byte array to the MemoryStreams.
Read More...
Any type of I/O operation you are performing in .NET, if you want to read or write data you eventually use a stream of some type. Streams are the basic mechanism. .NET uses to transfer data to and from its underlying source, it will be a file, communication pipe, or TCP/IP socket.
Read More...
There are many times you want to read text file. There are many ways to read files. One way is to use FileStream class. Here are sample example to read the file and display it's content on page.
Read More...
To remove rule you can use RemoveAccessRule methods. Here are sample Example.
Read More...
There is a situations where you want to modify the ACL lists. In this example, you give a specific user explicit Full Control rights over the file. You can use either an existing user or create a new test User account .
Read More...
There is a need to get the Access Control Lists or ACLs on directories and files. ACLs are the way resources such as directories and files are secured in the NTFS file system,which is the file system used by most recent versions of Windows. Manually you can view a file’s ACLs by selecting the Security tab from the file’s Properties dialog.
Read More...
.NET Framework provides you with a class for working with file paths. The System .IO.Path class has many static methods to work with paths. Some static methods are...
Read More...
When an ASP.NET page is executed, the thread used to execute the code that generates the page by default has a current working directory of that page. It uses this directory as its base directory . If you pass a relative filename into any System.IO class, the file is assumed to be located relative to the current working directory.
Read More...
Sometimes we want list of files and its details like file name , size , last access time etc... of a directory programmatically. We can achieve this using DirectoryInfo and FileInfo Class. These classes are available in available in System.IO Namespace.
Read More...
Some time you want to get directory information like sub directories , last access time , last write time , Create new directory in to parent directory etc... programmatically using .Net.
Read More...
You can get Drive info using DriveInfo class. DriveInfo class available in System.IO Namespace. You can get details like name, type, size, and status etc... of each drive.
Read More...
No comments:
Post a Comment