473,387 Members | 1,516 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

about exception while writing in a file by filestream in c#

I am writing some content in xml which i m getting from a url.
I am using filestream for this but i am getting "null reference exception " ny body have ny idea?? plz help me...
urgent ..
following is code ..

Expand|Select|Wrap|Line Numbers
  1. public void StoreFeedData(string title,Uri url)
  2.         {
  3.             XmlDocument xmldoc = new XmlDocument();
  4.  
  5.             XmlElement rss = xmldoc.CreateElement("rss");
  6.             XmlElement rsstitle = xmldoc.CreateElement("title");
  7.             rsstitle.InnerText = title;
  8.             rss.AppendChild(rsstitle);
  9.             XmlElement rsslink = xmldoc.CreateElement("link");
  10.             rsslink.InnerText = url.ToString();
  11.             rss.AppendChild(rsslink);
  12.             xmldoc.DocumentElement.InsertAfter(rss, xmldoc.DocumentElement.LastChild);
  13.  
  14.             //INSTANCE OF FILE IS CREATED 
  15.             FileStream fs = new FileStream(@"\\Program Files\\RssFeed\\feedlist.xml", FileMode.Append, FileAccess.Read);
  16.             //xmldoc.Load(fs);
  17.             //XML DOCUMENT SAVED
  18.             xmldoc.Save(fs);
  19.             fs.Close();
  20.  
  21.  
Oct 8 '10 #1
4 1710
GaryTexmo
1,501 Expert 1GB
Which line is generating the null reference exception?

I can't help but wonder if it's line 15 in your example, is that path valid? Wouldn't you need a "C:" in front of that so it knows where to find "Program Files"?
Oct 8 '10 #2
Curtis Rutland
3,256 Expert 2GB
Line 15 is for sure a problem.

@ denotes a verbatim string literal, meaning that nothing is escaped, including backslashes.

That line must fail, because there is no such path as \\Program Files.

Either remove the @, or better, remove the excess backslashes:
Expand|Select|Wrap|Line Numbers
  1. @"c:\Program Files\RssFeed\feedlist.xml"
Also, include the drive letter.
Oct 8 '10 #3
hi curtis... thanx for reply. I tried ur option but still its not working. I tried to debug and its line 12 which is throwing exception.
Oct 11 '10 #4
Curtis Rutland
3,256 Expert 2GB
Please be more specific. What error is thrown? The name and the message, please.
Oct 11 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: vince | last post by:
MSDN help says you can use a UNC path for any methods that accept a path, and I'm wondering if I can also substitute an IP address for the UNC....??? Example: Using System.IO.File.Move() ...
0
by: JC | last post by:
I am using Mysql version: 4.0.18-max-log and trying to populate a database from a text file using source option from inside the mysql environment. The population run OK but when creating the...
0
by: yindevil | last post by:
I have a problem about import .ocx file When i add the ocx file in the reference, i can see the method.. http://www.groupx.net/yindevil/cm11.gif but when i try to call the ocx file.. ...
9
by: C# Learner | last post by:
Some time ago, I remember reading a discussion about the strengths and weaknesses of exception handling. One of the weaknesses that was put forward was that exception handling is inefficient (in...
1
by: Maheshkumar.R | last post by:
Hi all, I'm new bie to windows application..i want to search a key word inside a file..let say, if a file contains text "this is sample program...". If i search "sample" inside a file, it should...
1
by: Robin Tucker | last post by:
I keep reading about exception handling being preferable to "return codes". I would like to implement some kind of consistent use of exceptions in my code, but am finding it hard to come up with...
10
by: David Thielen | last post by:
Hi; I am trying to write to the event log using: public const string EVENT_LOG_NAME = "Windward Portal"; if (!EventLog.SourceExists(EVENT_LOG_NAME)) EventLog.CreateEventSource(EVENT_LOG_NAME,...
1
by: Mr fahad | last post by:
#include <stdio.h> #include <conio.h> void main (void) { char ch; FILE *fp; fp=fopen ("fahd.txt","w"); while (ch=fgetc( )!='\r') fputc (ch,fp); fclose (fp);
11
by: George2 | last post by:
Hello everyone, How do you understand the Bjarne's comments about exception specification? Especially, "not required to be checked across compilation-unit" and "violations will not be caught...
1
by: tarun02kumar | last post by:
hello everyone, I am new to python so I need help about the .pyd file I have a name.pyd file which basically is a merge of many .h5 data files. I have to use this .pyd files(merge of simulations...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.