如何从c#中的服务器下载文件....我的代码下面是 [英] how to download file from the server in c# .... below my code is

查看:143
本文介绍了如何从c#中的服务器下载文件....我的代码下面是的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里我的代码





以及如何获得索引值的列名



  public   static   void  savefile_XML( string  EmpId, string  FirstName, string  LastName, string  MiddleName, string 性别, string  DateOfBirth, string  MobileNo, string  EmailId,字符串地址,字符串区,字符串状态, string 国家/地区,字符串 zip)
{

TR y
{


string [] arr1 = new string [] {EmpId,FirstName,LastName,MiddleName,Gender,DateOfBirth,MobileNo,EmailId,Adress,District,State,Country,zip} ;
XmlDocument xmlDoc = new XmlDocument();
XmlElement element = xmlDoc.CreateElement( data);

for int i = 0 ; i < arr1.Length; i ++)
{
XmlElement element1 = xmlDoc.CreateElement((i)。的ToString()); ;
element1.InnerText = arr1 [i];
element.AppendChild(element1);
xmlDoc.AppendChild(element);



}

xmlDoc.Save( @ F:\ srikanth \ jqgrid \ test.xml);

}

catch (例外情况)
{
Elmah.ErrorLog.GetDefault (HttpContext.Current)。Log( new Elmah.Error(ex,HttpContext.Current));
}









这里我喜欢这个< pre lang =xml> < 0 > 2020 < / 0 >
< 1 > narendra < / 1 >
< 2 > modi < / 2 >
< 3 > n < / 3 >





列出名称的iwant数字可以告诉代码.....以及如何将该文件保存到我们当前的项目中......以及如何下载保存的文件。 .plz帮助...我不是没有xml ...新的xml ........

解决方案

而不是使用

 CreateElement((i).ToString()); 



使用

 CreateElement((tagName)); 



其中tagName可以是例如FirstName或LastName,因此它最终在XML标记中作为

 <  名字 >   <   / firstname  >  



要以最简单的方式执行此操作,请创建一个包含文字字符串的字段数组这:

  string  [] fields = {  FirstName  LastName  Id};  //  等..  



(i).ToString()

with

 fields [i] 



这应该可以解决你的问题。


使用这个代码解决了我自己....在这段代码的帮助下,我发现了一个列名.....

< br $>


string EmpId = string.Empty;

var objects = JArray.Parse(getdata);

XmlDocument xmlDoc = new XmlDocument();

XmlElement element = xmlDoc.CreateElement(details);



foreach(对象中的JObject root)

{

foreach(KeyValuePair< string,> root in root)

{

var appName = app。 Key; //在这个app.key中获取列名

EmpId =(String)app.Value; //我们可以获得empid

XmlElement element1 = xmlDoc.CreateElement(appName);

element1.InnerText =(String)app.Value;

element.AppendChild(element1);

xmlDoc.AppendChild(element);

}

}


here my code
is

and how to get column names insted of indexvalues

public static void savefile_XML(string EmpId, string FirstName, string LastName, string MiddleName, string Gender, string DateOfBirth, string MobileNo, string EmailId, string Adress, string District, string State, string Country, string zip)
    {
        
        try
        {
           

                string[] arr1 = new string[] { EmpId, FirstName, LastName, MiddleName, Gender, DateOfBirth, MobileNo, EmailId, Adress, District, State, Country, zip };
                XmlDocument xmlDoc = new XmlDocument();
                XmlElement element = xmlDoc.CreateElement("data");

                for (int i = 0; i < arr1.Length; i++)
                {
                    XmlElement element1 = xmlDoc.CreateElement((i).ToString()); ;
                    element1.InnerText = arr1[i];
                    element.AppendChild(element1);
                    xmlDoc.AppendChild(element);



                }
               
                xmlDoc.Save(@" F:\srikanth\jqgrid\test.xml");
            
 }

        catch (Exception ex)
        {
            Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex, HttpContext.Current));
        }





here iam getting like this

<0>2020</0>
  <1>narendra</1>
  <2>modi</2>
  <3>n</3>



iwant numbers insted of column names can u tell the code .....and how to save that file into our current project ...and how to download saved file ..plz help ...i dont no xml..iam new to the xml........

解决方案

Instead of using

CreateElement((i).ToString());


Use

CreateElement((tagName));


Where tagName could be for example FirstName or LastName, so it ends up in the XML tag as

<firstname></firstname>


To do this in the simplest way, create an array of fields holding literal strings like this:

string[] fields = {"FirstName", "LastName", "Id"}; //etc..


Replace the

(i).ToString()

with

fields[i]


This should solve your problem.


solved my self using this code ....iam geting column name with help of this code.....


string EmpId = string.Empty;
var objects = JArray.Parse(getdata);
XmlDocument xmlDoc = new XmlDocument();
XmlElement element = xmlDoc.CreateElement("details");

foreach (JObject root in objects)
{
foreach (KeyValuePair<string,> app in root)
{
var appName = app.Key;//in this app.key getting column name
EmpId = (String)app.Value;// we can get empid
XmlElement element1 = xmlDoc.CreateElement(appName);
element1.InnerText = (String)app.Value;
element.AppendChild(element1);
xmlDoc.AppendChild(element);
}
}


这篇关于如何从c#中的服务器下载文件....我的代码下面是的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆