.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

File Stream

Posted By:      Posted Date: September 07, 2010    Points: 0   Category :ASP.Net
i want to open a text file and want to search a particular string if exist print that string on a text box using c#.net

View Complete Post

More Related Resource Links

File Stream Class

 I am trying to write to a text file while protecting it from concurrent access. What is the advantage of fileStream.lock ? (when I created a filestream in the code below, the file seemed to be protected from other processes using it). I am not sure if I need to use filestream.lock below. Please advise ..            Public Shared Sub writeToLogFile(ByVal logMessage As String)         Try             Dim strLogMessage As String = String.Empty             Dim strLogFile As String = System.Web.HttpContext.Current.Server.MapPath("~/Log.txt")             Dim swLog As StreamWriter             strLogMessage =  DateTime.Now.ToLongTimeString().ToString() & " ==> " & logMessage             Dim fileStream As New FileStream(strLogFile, FileMode.Append)            ' Lock all of the file after creating the filestream object             fileStream.Lock(0, fileStream.Length)      &nb

Cannot read stream from uploaded file

I have a file upload which uploads a file and gets read into a byte array.int FileLength = File1.PostedFile.ContentLength; if (File1.PostedFile != null && File1.HasFile) { Stream fStream = File1.PostedFile.InputStream; byte[] contents = new byte[fStream.Length]; fStream.Read(contents, 0, (int)fStream.Length); fStream.Close(); fStream.Dispose(); The problem is, the fStream.Read seems to have a problem reading the stream. When I debug it, and the value of "contents" appears to be empty. The file gets uploaded as a corrupted file.  

Stream Writer encoding when creating excel file

I am working on an application in which i save save html files which have ISO-8859-1 encoding (The html files are in spanish).
I use stream writer to save the source of the files as excel files.
The problem is the encoding options available in the system.text.Encoding class are
so when I save the page it changes certain characters.
<big>Can Any 1 suggest which encoding i should use ... </big>

Using response.outputstream.write to stream large file fails in firefox



I have some code to stream files (for security of the files), the code works for all files in IE, and small files in firefox. but If the file is large (eg 750Mb) firefox hangs before it shows the open/save dialog box. 

However if i take out response.clearheaders and the response.flush in the code it does download but all the files downloaded by firefox are corrupt because the file size is too large.   Filenames are guids but I took the "-" out incase that was an issue.

If any one can shed some light on this I would be very grateful.

Function is Below. 


Private Sub StreamFile(ByRef response As HttpResponse, ByVal sFile As String)
            Dim fs As FileStream = Nothing
            Dim sFileName As String = Path.GetFileName(sFile)

            Dim oFile As New FileInfo(sFile)

                fs = New FileStream(sFile, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)

            Catch ex As Exception

            End Try


            'response.ClearHeaders() 'makes file size wrong in firefox
            response.AddHeader("Content-Length", oFile.Length)
            'To forcefully download, even for Excel, PDF files, reg

Custom File Stream Result error when the client connection is closed


I recently notice that on our MVC 2.0 web app that does images retrieval,  we have this error when the user close the browser before image file is done transmitting :

TypeName: System.Web.HttpException

TypeAssembly: System.Web, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Message: The remote host closed the connection. The error code is 0x80070057.

Source: System.Web

TargetSite: Void RaiseCommunicationError(Int32, Boolean)

StackTrace:    at System.Web.Hosting.IIS7WorkerRequest.RaiseCommunicationError(Int32 result, Boolean throwOnDisconnect)

   at System.Web.Hosting.IIS7WorkerRequest.ExplicitFlush()

   at System.Web.HttpResponse.Flush(Boolean finalFlush)

   at System.Web.HttpResponse.End()

   at CT.iMagio2.Apps.Web.Search.Controllers.ControllerActionResultInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)

   at System.Web.Mvc.ControllerActionInvoker

File Stream Folders / Files still in file system


Hi All,


I have dropped and re-created a table that contains filestream columns.  When I have done this I see that the original folders / files still exist out on the file system.  How is it that these will get removed since the orignal table(s) have been dropped and re-created?

Looks like the folders are always two levels deep.  What does each represent? I can see the actual files, but what do the parent / child folders represent?

I also see the F$log folder.




Xml File/Stream from SharePoint BDC webpart list



Im trying to create an XMl File or stream from a SharePoint BDC which displays the data as a list.

Theres the option to use owssvr.dll to get what im after from a standard list with just het site name and GUID

example:  http://server/sites/_vti_bin/owssvr.dll?Cmd=Display&List={GUId}&XMLDATA=TRUE

Is there a way to use this with the BDC web part? THe BDC creates what it calls a list and looks the same as a normal SharePoint List, but it grabs the data on page load and does not have a GUID for the list not what i could spot anyway

MOSS 2007




Stream a PDF file into a page


I have been trying without any success to get a PDF file to stream into a page.

The PDF file is generated / hosted on another domain (our own same server but 3rd party software)

I've trawled the Net and tried to use / adapt some examples but I get nothing at all in the page. 

Ideally if I could also wrap it up in a user control that returns the PDF that would make life easier.

Anyone know of any good reliable code (VB preferably) that would help with this.

Many Thanks.

File Splitter in .Net

I love to do utility programs in .Net. And this is one of them. As I was playing with JSplit (a free file splitter program), I wondered if I could do it in .Net. The framework supports file operations like reading files in bytes and creating them. It is indeed easy to do file operations in .Net Basics on File operations

Upload Multiple File using JQuery in asp.net

In this article I have explained how to upload multiple files using file upload control. I have used jQuery plugin for uploading multiple files.

I have also explained how to check for file type, file maximum size limit using jQuery & also using server side validation code.

Creating Excel file from C#

I used below coding for create a excel sheet.I got from on web site.
In below coding there is no problem.Its create the excel file.If i run second time,its ask to overwrite the current excel file.If I said "Yes" then it ok ,but If I select cancel button,its generate the Error message.The exception is

Upload a File to a SharePoint Document Library - Part I

The following helper class demonstrates a few techniques that allow documents to be uploaded to a SharePoint document library programmatically without using the API or a custom web service. You don't need to specify a document library name, and it will create any folders specified in the URL as required. File meta data will be updated if any properties are passed.

SmtpClient and Locked File Attachments

Got a note a couple of days ago from a client using one of my generic routines that wraps SmtpClient. Apparently whenever a file has been attached to a message and emailed with SmtpClient the file remains locked after the message has been sent. Oddly this particular issue hasn't cropped up before for me although these routines are in use in a number of applications I've built.

How to call an .exe file in .net

Sometimes a developer has to call an EXE from another EXE. While calling EXE there can be a requirement to pass parameter.

ClientAccessPolicy file in SharePoint 2010

I am upgrading my Silverlight demo code from the old beta to beta 2 and see that there are a few new considerations for the deployment of ClientAccessPolicy.xml files. In a previous post I demonstrated how to do this for SharePoint 2007. The heartburn that I get with that approach is any site collection owner or designer can drag the file into the site collection and open the site up to unwanted client access issues. In 2010 the virtual path provider no longer serves the files from the root of the site collection

Multi File Upload Using JQuery!

Everyone knows about the file upload in .NET. But the multi file upload is some what difficult in .NET. For that purpose we can have some AJAX or JQuery!. Jquery is the latest advanced version. It will give some animated upload. You can try it for your own!!!!

Transfering a file from Conputer to PDA

You can transfer one file at a time between your computer and another Bluetooth device by using the Bluetooth File Transfer Wizard. For example, you can transfer files between your computer and a mobile phone or a PDA. You can also transfer files between two computers that use Bluetooth.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend