Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading the contents of a file in sharpsvn

Tags:

.net

sharpsvn

I'm trying to read the contents of a .csproj file using sharpsvn, but I seem to be always getting an empty file back.

Here is my code:

MemoryStream myOut = new MemoryStream();       
svnClient.Write(path, myOut))
return myOut.GetLibsFromCsproj();

private static string GetLibsFromCsproj(this MemoryStream csjpros)
{
    TextReader tr = new StreamReader(csjpros);
    XElement projectNode = XElement.Load(tr);
    XNamespace msbuild = "http://schemas.microsoft.com/developer/msbuild/2003";
    var referenceNodes = projectNode.Descendants(msbuild + "ItemGroup").Descendants(msbuild + "Reference").ToString();
    return referenceNodes;
}

When my code gets to XElement.Load(tr);, it throws an error saying that root element is missing. It turns our that myOut is empty.

Am I doing something wrong?

like image 598
RJP Avatar asked Jun 01 '12 16:06

RJP


2 Answers

Did you remember to reset the MemoryStream back to the beginning after writing into it? Try adding this line before the return statement:

myOut.Seek(0, SeekOrigin.Begin);
like image 181
Allon Guralnek Avatar answered Nov 19 '22 04:11

Allon Guralnek


perhaps this is helpful:

How to read each revision of file using sharpsvn client using c#

like image 45
Mare Infinitus Avatar answered Nov 19 '22 02:11

Mare Infinitus