지금까지 ftp 서버에서 파일을 다운로드 한 다음 제 3 자 dll (미디어 정보)을 사용하여 파일에 대한 메타 데이터 세부 정보를 얻는 코드를 작성했습니다. 이 좋은 때까지, 지금 내 출력을 기반으로 XML 파일을 생성하려고 오전, 좋은 예제를 본 여기에 How can I build XML in C#? xml 생성하려면 내 시나리오가 조금 다르다, 왜 내가이 스레드를 만들었습니다. 아래 출력에서 xml 파일 생성
은 JPG 파일의 속성 값을 얻을 수있는 코드static void Main(string[] args)
{
try
{
string file = "test.jpg";
FtpWebRequest reqFTP;
string ftpserverIp = "1.0.0.1";
string fileName = @"c:\downloadDir\" + file;
FileInfo downloadFile = new FileInfo(fileName);
FileStream outputStream = new FileStream(fileName, FileMode.Append);
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpserverIp + "/" + file));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.KeepAlive = false;
reqFTP.Timeout = -1;
reqFTP.UsePassive = true;
reqFTP.Credentials = new NetworkCredential("sh", "SE");
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
// reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
int bufferSize = 4096;
int readCount;
byte[] buffer = new byte[bufferSize];
readCount = ftpStream.Read(buffer, 0, bufferSize);
Console.WriteLine("Connected: Downloading File");
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
Console.WriteLine(readCount.ToString());
}
ftpStream.Close();
outputStream.Close();
response.Close();
Console.WriteLine("Downloading Complete");
var message = new StringBuilder();
ConsoleApplication2.Program TechMeta = new ConsoleApplication2.Program();
TechMeta.PutMessage(file, message);
Console.WriteLine(message);
}
catch (Exception ex)
{
Console.Write(ex);
}
}
private void PutMessage(string filename, StringBuilder message)
{
//Check the file is video or Image file here
string extension =".jpg";
bool b;
if (b = filename.Contains(extension))
{
HowToUse_Dll.ImageInterrogator imageInterrogator = new HowToUse_Dll.ImageInterrogator();
imageInterrogator.LoadFile(filename);
message.AppendFormat(messageFormat, "Width", imageInterrogator.GetWidth(), Environment.NewLine);
message.AppendFormat(messageFormat, "Height", imageInterrogator.GetHeight(), Environment.NewLine);
message.AppendFormat(messageFormat, "FileSize", imageInterrogator.GetFileSize(), Environment.NewLine);
message.AppendFormat(messageFormat, "FileFormat", imageInterrogator.GetFileFormat(), Environment.NewLine);
message.AppendFormat(messageFormat, "Resolution", imageInterrogator.GetResolution(), Environment.NewLine);
}
else
{
HowToUse_Dll.VideoInterrogator videoInterrogator = new HowToUse_Dll.VideoInterrogator();
videoInterrogator.LoadFile(filename);
message.AppendFormat(messageFormat, "FileSize", videoInterrogator.GetFileSize(), Environment.NewLine);
message.AppendFormat(messageFormat, "Duration", videoInterrogator.GetDuration(), Environment.NewLine);
message.AppendFormat(messageFormat, "AspectRatio", videoInterrogator.GetAspectRatio(), Environment.NewLine);
message.AppendFormat(messageFormat, "GetAspectRatio", videoInterrogator.GetAspectRatio(), Environment.NewLine);
message.AppendFormat(messageFormat, "BitRate", videoInterrogator.GetBitRate(), Environment.NewLine);
message.AppendFormat(messageFormat, "Format", videoInterrogator.GetFormat(), Environment.NewLine);
message.AppendFormat(messageFormat, "VideoCoder", videoInterrogator.GetVideoCoder(), Environment.NewLine);
message.AppendFormat(messageFormat, "Redirector", videoInterrogator.GetRedirector(), Environment.NewLine);
message.AppendFormat(messageFormat, "TargetPlayback", videoInterrogator.GetTargetPlayback(), Environment.NewLine);
}
}
public string messageFormat
{
get
{
return "{0}: {1}{2}";
}
}
test.jpg를 파일 그것은, TechMeta.PutMessage (파일, 메시지)에 대한베이스; 메시지 값은
{Width: 1024
Height: 576
FileSize: 84845
FileFormat: JPEG
Resolution: 8
}
이제 다음과 같은 값을 기반으로 XML 파일을 생성하기 위해 노력하고 있으며, 더 중요한 것은
<image Name="test.jpg">
<width>1024</width>
<height>576</height>
<file-Size>84845</file-Size>
<resolution>8</resolution>
<image Name="test1.jpg">
<width>1024</width>
<height>576</height>
<file-Size>84845</file-Size>
<resolution>8</resolution>
아래 어떤 제안 같은 새로운 파일을 기반으로
를하시기 바랍니다 추가하는 것을 시도하고있다
무엇을 시도 했습니까? 우리는 당신의 코드를 작성하기 위해 여기에 온 것이 아닙니다. 붙어 있다면 우리는 당신을 도울 수 있지만, 당신이 정확히 당신의 문제인지 말해야합니다. – svick
@svick 어떤 사람이 나를 위해 코드를 작성하는 것을 기대하지 않고, 내 출력에서 XML을 생성하는 데 더 좋은 방법이나 최선의 방법을 제안합니다. 예를 들어 xsd 파일을 생성하거나 xmldocument 등을 사용합니다. bcoz는 xml 그 이유는 내가 여기에 던져이 질문을 – Usher
당신은 "더 나은 방법"을 요구하고 있지만, 당신은 무엇보다 말하지 않습니다. 먼저 직접 시도한 다음 작동하지 않거나 더 나은 방법이 있어야한다고 생각하면 Google에 문의하십시오. 또한 XML이 유효하지 않고 ''요소를 닫지 않으며 XML에 여러 루트 요소가있는 것 같습니다. –
svick