2011-11-03 2 views
0

나는 samplexml.xml이라는 xml 파일을 가지고 있으며 SampleFolder라는 폴더에 저장했습니다. 계층 구조는 다음과 같습니다.솔루션에서 파일 찾기

솔루션 -> 프로젝트 -> SampleFolder-> samplexml.xml. 프로젝트에있는 TestClass.cs라는 클래스에 있다고 가정합니다. xml 파일의 모든 내용을 문자열로 읽을 수있는 방법은 무엇입니까?

의가 있다고 가정 해 봅시다

,

[TestClass] 
public class TestClass 
{ 
    [TestMethod] 
    public void TestMethod() 
    { 
     //TODO: Read all the contents of the xml file in a string. 
    } 

} 

어떻게이해야합니까?

+0

아브라카 다 브라로 XML 파일을 복사하는 컴파일러를 설정해야합니다 기억하십시오! – Arun

+0

XMLReader를 사용하십시오 ... 사용하려고 시도조차하지 않았기 때문에 실제 연습 문제 일 수 있습니다. –

답변

0

시도 :

string exePath = Path.GetDirectory(Assembly.GetExecutingAssembly().Location); 
string xmlPath = Path.Combine(exePath, "SampleFolder"); 
string fileName = Path.Combine(xmlPath, "SampleXML.xml"); 

당신이 디렉토리 목적지

+0

고맙습니다. 저에게 좋습니다. – DotNetUser