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

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

File.AppendAllText method writes garbage?

Posted By:      Posted Date: September 08, 2010    Points: 0   Category :.NET Framework
When I execute the below code multiple times on a file, it writes garbage values in file...    string msg = "Ajmera";  File.AppendAllText("F:\\deep.txt", msg);     File content after 15-20 writes :-  ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? Why does it happens?

View Complete Post

More Related Resource Links

Calling parameterized method from aspx file


Hi all,
I have following method
 public string GetYoutubeVideo (string code)
        return "asasdasfa"

why I can not upload file to web by using WebClient.UploadFile method?



I am using WebClient.UploadFile method to upload a file to a web page.

The code is like this:

WebClient client = new WebClient(); 
byte[] responseBinary = client.UploadFile(url, fileName); 
string response = Encoding.UTF8.GetString(responseBinary);

But I can not upload it to server.

I used fiddler to see what happens, and it shows me the following information:

http status code: 302, request headers: POST /testing/upload/default.aspx HTTP/1.1

http status code: 302, request headers: GET /testing/upload/default.aspx?AspxAutoDetectCookieSupport=1 HTTP/1.1

http status code: 200, request headers: GET /(X(1)S(22pynhvxd3eqsb455pudx145))/testing/upload/default.aspx?AspxAutoDetectCookieSupport=1 HTTP/1.1

I would like to know, why I get 302 code, and why it redirect me to the strange url with (X(1)S(22pynhvxd3eqsb455pudx145)) ?

By the way, the web page is ok to upload file by using web explorer.


Method/Way to know whether a input path of FilesSystem contains any Child file/folder or not

Hi,I am looking for a Method/Way to know whether a input path of FilesSystem contains any Child file/folder or not. To know it currently I am using "Directory.GetFileSystemEntries(Path).Count" and checking if count > 0 then returning True else False. For this first method calculates all the files and folder and then return status to me but I want to exit out as soon as my method gets first element(file/folder) in specified path. Because above method is timing out when my input path contains more than 1 million files. I just need to check whether input folder path contains any child file/folder or not. I have tried to use Win32 API also but on ther server it is crashing so I donot want to use that solution. In .NET any method or way is present to know it. Please suggest me.

How to set and map a Method in the Service file with endpoint elements and binding elements

Hi all, I have created a service file like OSService.svc in that i have two methods like one is FileUpload and FileDownload for e.g :- [WebInvoke(UriTemplate = "/fileupload/{fileName}" , Method = "POST" )]         [OperationContract]         void FileUpload(string fileName, Stream fileContents); same as Filedownload also. People you may know these methods are inside the interface of service file what you are using i'e i have created a interface as IOSService.cs. So, what i need now is i want to write separate endpoint for FileUpload and Filedownload.Because i want to set separate value for receiveTimeout  and openTimeout for the Fileupload and FileDownload process in binding section in the web.config file itself. The below code was i'm using right now but still i'm not able to the set separate value of endpoint elements in the bindings. EndPoint Section:- <endpoint name = "endPoint1"  address  = "localhost:8000/OSService.svc/" bindingConfiguration = "TransactionalTCP"   binding  = "netTcpBinding"          contract = "IOSService"/> Binding Section:-  <binding name = "TransactionalTCP"  transactionFlow = "true"   /&

if ssis package writes to excel file that might be open by a user

I have written a package that writes to an excel file to a network folder. Eventually this package will run as a job. What is the best way to handle the situation where someone opens the file or inadvertantly leaving it open while the package is running and and stop the package.? No one needs to modify or write anything to this file after it is finished

Arrange columns from nested table in a dataset that writes into XML file



I have 3 related data tables. I added these tables into a dataset and finally write it to a XML file. But the related columns from table 2 and 3 is appended after all the columns from table 1. How can I have something like:
in a dataset that I write to XML instead of

How to read all function/method names from .cs file


 Hi everyone,

Normally i answer to the peoples questions here but today i am posting a question for a answer :)

I have a .cs file and i want to read all function/method names from it.

This .cs file is not part of my project or solution other wise i would have used reflection or codedom to do so.

The .cs file is a file on a disk to which i can accessing by giving its physical path say "C:\Sample.cs"

Is there any possibility that i can fetch all the function names declared in Sample.cs

Note: I am doing this for one of my requirement to find out dependencies in code

For example If class A is using some function from class B then class A is dependent on class B. this i need to find out and both this class files are simply a files residing on disk not even part of my project. 

User will select a directory first then any one of the .cs file in that directory and will click on button to find dependencies of that .cs file.

The application should traverse all other .cs files in that directory and find out on how many other .cs files the selected file is dependent.

Send Email with HTTP file attachment - Workflow is sending garbage in attachment



I'm having an issue with a customized workflow when I send an email with an attachment. I am using the "send email with http file attachment" that I have downloaded from CodePlex. Unfortunately all attachments that come through are full of garbage. This includes .jpg, .pdf, and .txt. From what I can tell with the .txt file is that its contents has been replaced with what appears to be the html of the list page. Both the .jpg and .pdf fail to open complaining about corrupt documents. All documents can be opened fine from within sharepoint. 

Can anyone of you guide me in this regard, as rest of my  workflow logic is working fine but this attachment issue is ruining the end result.


sql job outputs garbage bytes at beginning of file



on one of my servers, any new sql job i create that outputs to a file has started putting 4 bytes at the head of each file.  the bytes are "ff fe 4a 00".    all existing jobs do not do this, only new jobs that are created.   this happens regardless of where i direct the output, or whether it's a tranact sql or CMDEXEC type job.  and it's only on this server.

any ideas, hints, etc.?

thanks much,


how to call a session variable in Web service Method in Default.cs file



I have used a web service method in my Application. And as per the requirement using one user. I am searching for a list of schools to a particular area. When one person logged with the credentials , search criteria works fine when another person logs in there the problem like session variable is getting overriden . This is a issue which I am facing and as per its very urgent to solve the problem. Please help me and solve the Issue.

Please repond Immediately, as I am unable to sleep at nights.

I am also sending the code of a sample example 


using System;
using System.Configuration;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
    //public string str;
   // SharedPersonalizationStateInfo string str;
    static string str1;
    static string strName;
    static  string strSqlquery;
    protected void Page_Load(object sender, EventArgs e)

        if (!IsPostBack)
            strName = Session["ID"].ToString();
            str1 = Session["FriendID"].ToString();

Delete file in a subfolder using Updatelistitems web method



I need to delete zip file under my folder and sub folders which are under the list name named "Documents", so i used



GetListItems web method and got the list zip files. When i try to delete the same i am not able to delete the ones that are in the folders (i.e) if the zip file is under [http://server/mysite/Documents/Folder/aaa.zip].

I am adding the line of code which am using for deleting the file from the list.

 XmlDocument xmlDoc = new System.Xml.XmlDocument (); 

Thinking about new C# method prototypes: object as dictionary

I recently had to write a small Flickr API. I know many .Net API for Flickr already exist but I needed one for a Silverlight application. Whatever, it's only about building some querystrings so I did it by myself. It's been an opportunity to think again about a classical question: how to pass parameters to a method ?

Imagine you have a generic method to call some Flickr functions.

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.
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