473,385 Members | 1,856 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,385 software developers and data experts.

will this code work????

public string GetFile(string objXml)
{
XmlDocument xmlINPUT = new XmlDocument();
xmlINPUT.LoadXml(objXml);
string directoryName =
xmlINPUT.GetElementsByTagName("DIRECTORY")[0].Value.ToString();
string fileName =
xmlINPUT.GetElementsByTagName("FILE")[0].Value.ToString();

XmlDocument xmlOUTPUT = new XmlDocument();
XmlElement xmlROOT = xmlOUTPUT.CreateElement("ROOT");
xmlOUTPUT.AppendChild(xmlROOT);
XmlElement xmlFILE = xmlOUTPUT.CreateElement("FILE");
xmlFILE.SetAttribute("NAME",fileName);

/* Conversion of file into byte stream STARTS */
Byte[] byteFILE;
FileStream fs = new
FileStream("\\"+directoryName+"\\"+fileName,System .IO.FileMode.Open,System.IO.FileAccess.Read);
byteFILE = new byte[fs.Length];
BufferedStream bs = new
BufferedStream(fs,Convert.ToInt32(fs.Length));
char[] charFILE = new char[byteFILE.Length];
for(int i = 0; i < fs.Length; i++)
{
byteFILE[i] = (byte)bs.ReadByte();
charFILE[i] = Convert.ToChar(byteFILE[i]);
}
string stringFILE = charFILE.ToString();
/* Conversion of file into byte stream ENDS */
xmlFILE.AppendChild(xmlOUTPUT.CreateCDataSection(s tringFILE));
xmlROOT.AppendChild(xmlFILE);
return xmlOUTPUT.InnerXml.ToString();
}

Sep 27 '06 #1
4 1102

The function accepts xml string which is:
<ROOT>
<DIRECTORY NAME="DOCUMENTS">
<FILE>file1.txt</FILE>
</DIRECTORY>
</ROOT>

and takes this file from drive and converts it into a character array
to be fed into CDATA of xml.
i want to know if it's written correctly and whether it will work.

Sep 27 '06 #2
The questions are just begging to be asked:

Have you tried it?

If not, why not?

If so, does it?

"Saurabh" <on***********@gmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>
The function accepts xml string which is:
<ROOT>
<DIRECTORY NAME="DOCUMENTS">
<FILE>file1.txt</FILE>
</DIRECTORY>
</ROOT>

and takes this file from drive and converts it into a character array
to be fed into CDATA of xml.
i want to know if it's written correctly and whether it will work.

Sep 27 '06 #3

Saurabh wrote:
The function accepts xml string which is:
<ROOT>
<DIRECTORY NAME="DOCUMENTS">
<FILE>file1.txt</FILE>
</DIRECTORY>
</ROOT>

and takes this file from drive and converts it into a character array
to be fed into CDATA of xml.
i want to know if it's written correctly and whether it will work.
At least four problems with your code:

1) You're assuming an ISO-8859-1 encoding given the way you're reading
the data
2) You're making a false assumption about what char[].ToString does.
3) If the file length changes, you carry on reading
4) You're never closing the streams, which you should be doing
automatically with a "using" statement

Why not use a StreamReader to read the data from the file? It looks
like all you're trying to do in that section is read the text from a
file, which can be done with StreamReader.ReadToEnd much more simply.

Jon

Sep 27 '06 #4

Thanks Jon,i'll try the StremReader.

Sep 28 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nomen Nescio | last post by:
can anyone be so kind as to look at http://www.mysolution.ws/HYPOCRITE.php and let me know why it isn't passing the form data to http://www.mysolution.ws/insertHYPOCRITES.php for the most...
34
by: SeeBelow | last post by:
I see the value of a class when two or more instances will be created, but Python programmers regularly use a class when there will only be one instance. What is the benefit of this? It has a...
23
by: Antoon Pardon | last post by:
I have had a look at the signal module and the example and came to the conclusion that the example wont work if you try to do this in a thread. So is there a chance similar code will work in a...
7
by: John | last post by:
Hi: I want all objects of a class share the same set of data, which will be input from a file when the code start to run. In my design, I use static data member. The definition of the class is...
8
by: Eric Lilja | last post by:
Hello, I had what I thought was normal text-file and I needed to locate a string matching a certain pattern in that file and, if found, replace that string. I thought this would be simple but I had...
6
by: Geir Baardsen | last post by:
Hi! This is a routine for copying a recordset into a new order. It has worked fine under Win98. However, my client has changed to Win XP, and suddenly it doesn't work anymore. I keep getting the...
53
by: Zhiqiang Ye | last post by:
Hi, All I am reading FAQ of this group. I have a question about this: http://www.eskimo.com/~scs/C-faq/q7.31.html It says: " p = malloc(m * n); memset(p, 0, m * n); The zero fill is...
7
by: Peter Steele | last post by:
I have code to add a domain user to a local group but I'm not sure if it will work with NT domains or whether it will only work with Active Directory based systems. Here's the code: public void...
5
by: Lyle Fairfield | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/html/callnetfrcom.asp The Joy of Interoperability Sometimes a revolution in programming forces you to abandon all...
48
by: meyer | last post by:
Hi everyone, which compiler will Python 2.5 on Windows (Intel) be built with? I notice that Python 2.4 apparently has been built with the VS2003 toolkit compiler, and I read a post from Scott...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.