c# - Object reference not set to an instance of an object using ( READTOEND) -


i have following code download txt file using ftp , write file.

 ftp = (ftpwebrequest)webrequest.create("ftp://" + ftphost + ftpdir + "/sapvalidobjects.txt");  ftp.method = webrequestmethods.ftp.downloadfile;  ftp.usebinary = false;  ftp.credentials = new networkcredential(ftpuserid, ftppwd);  ftpwebresponse response = (ftpwebresponse)ftp.getresponse();  stream sresponse = response.getresponsestream();  streamreader srsapcostobjects = new streamreader(sresponse);  m_swsapcostcentres.write(srsapcostobjects.readtoend());  m_swsapcostcentres.close();  response.close();   m_swsapcostcentres = new streamwriter(properties.settings.default.sapint + @"\sapcostcentres" + ".txt"); 

in reason throws exception @

 m_swsapcostcentres.write(srsapcostobjects.readtoend()); 

am not sure why,some 1 please guide me.

i guess issue file trying write exists , opened application.

try delete file:

properties.settings.default.sapint + @"\sapcostcentres" + ".txt" 

if exists, before trying create again.

in code should add try catch , make sure either use using statement wrap disposable objects or call close method in catch or block streams , other objects closed.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -