[英]generate xml file from the Output
So far i wrote a code to download a file from ftp server then using 3rd party dll (media info) to get the metadata details about the file. 到目前为止,我编写了一个代码从ftp服务器下载文件,然后使用3rd party dll(媒体信息)获取有关该文件的元数据详细信息。 Until this am good,now am trying to generate the xml file based on my output ,i seen great examples here How can I build XML in C#?
直到一切顺利,现在我正在尝试根据我的输出生成xml文件,我在这里看到了很好的示例如何在C#中构建XML? to generate xml but my scenario is little bit different,thats why i created this thread.
生成xml,但是我的情况有点不同,这就是为什么我创建了这个线程。
below is the code to get the properties value of jpg file 以下是获取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}";
}
}
base on the test.jpg file it ,TechMeta.PutMessage(file, message); 基于test.jpg文件,TechMeta.PutMessage(file,message); Message value are
消息值是
{Width: 1024
Height: 576
FileSize: 84845
FileFormat: JPEG
Resolution: 8
}
Now am trying to generate xml file based on the value like below,the more importantly am trying to append based on new file like below 现在我试图根据如下所示的值生成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>
Any suggestion please 有什么建议吗
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.