问题:1.要将datagridview1 中显示的数据导出txt文件中,要打开一个对话框,让用户可以选择txt文件
保存的路径。这要要怎么办?2.程序编译后有*.exe的图标要改成我们自已的图标,从哪改?3.配置文件是app.config,里面有连接数据库的参数,要编译后我要手动修改数据库的连接,能修改吗?
保存的路径。这要要怎么办?2.程序编译后有*.exe的图标要改成我们自已的图标,从哪改?3.配置文件是app.config,里面有连接数据库的参数,要编译后我要手动修改数据库的连接,能修改吗?
右击解决方案下面的那个属性 -》 应用程序 下面有个资源,资源里面有个图标的,可以选择的
private void ExportExcel1()
{
string style = @"<style> .text { mso-number-format:\@; } </script> ";
string Ftile = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString();
Response.Clear();
Response.Buffer = true;
Response.Charset = "GB2312";
Response.AppendHeader("Content-Disposition", "attachment;filename=COM_" + Ftile + ".xls");
// Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
Response.ContentEncoding = System.Text.Encoding.UTF7;
Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
// Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
this.EnableViewState = false;
System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
this.Gvexel.RenderControl(oHtmlTextWriter);//GVDY 是Gridview的ID名称
Response.Write(style);
Response.Write(oStringWriter.ToString());
Response.End(); }
保存的路径。这要要怎么办?
FolderBrowserDialog可以选择路径的
2.VS上面可以设置
3.可以改
public static bool DataTableToTxt(DataGridView gridview, string strFileName, char strSplit)
{
if (gridview == null||gridview.Rows.Count==0)
return false; FileStream fileStream = new FileStream(strFileName, FileMode.OpenOrCreate);
StreamWriter streamWriter = new StreamWriter(fileStream, System.Text.Encoding.Unicode); StringBuilder strBuilder = new StringBuilder(); try
{
for (int i = 0; i < gridview.Rows.Count; i++)
{
strBuilder = new StringBuilder();
for (int j = 0; j < gridview.Columns.Count; j++)
{
strBuilder.Append(gridview.Rows[i].Cells[j].Value.ToString() + strSplit);
}
strBuilder.Remove(strBuilder.Length - 1, 1);
streamWriter.WriteLine(strBuilder.ToString());
}
}
catch(Exception ex)
{
string strErrorMessage = ex.Message;
return false;
}
finally
{
streamWriter.Close();
fileStream.Close();
} return true;
}
public void SaveConfig(string configKey,string configValue)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Clear();
config.AppSettings.Settings.Add(configKey, configValue);
config.Save();
}
public void SaveConfig(string configKey,string configValue)
{
XmlDocument doc=new XmlDocument();
doc.Load(strFileName);
XmlNodeList nodes=doc.GetElementsByTagName("add");
foreach (XmlNode node in nodes)
{
XmlElement xe = (XmlElement)node;
if (xe.GetAttribute("key") == configKey)
{
xe.SetAttribute("value", configValue);
}
}
doc.Save(strFileName);
} public void SaveConfig(string configKey,string configValue)
{ for (int i = 0; i < nodes.Count; i++)
{
XmlAttribute att = nodes[i].Attributes["key"];
if (att.Value == "" + configKey + "")// if(att.Value == configKey)
{
att = nodes[i].Attributes["value"];
att.Value = configValue;
break;
}
}
doc.Save(strFileName); } public static string GetConnectionStringsConfig(string connectionName)
{
try
{
string connectionString =
ConfigurationManager.ConnectionStrings[connectionName].ConnectionString.ToString();
Console.WriteLine(connectionString);
return connectionString;
}
catch
{
return "";
}
} public static void UpdateConnectionStringsConfig(string newName, string newConString, string newProviderName)
{
bool isModified = false;
if (ConfigurationManager.ConnectionStrings[newName] != null)
{
isModified = true;
}
ConnectionStringSettings mySettings =
new ConnectionStringSettings(newName, newConString, newProviderName);
Configuration config =
ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);//ConfigurationUserLevel.None
if (isModified)
{
config.ConnectionStrings.ConnectionStrings.Remove(newName);
}
config.ConnectionStrings.ConnectionStrings.Add(mySettings);
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("ConnectionStrings");
} public static string GetAppSettings(string SettingName)
{
return ConfigurationManager.AppSettings[SettingName].ToString();
}
public static void SetAppSettings(string AppKey, string AppValue)
{
XmlDocument doc = new XmlDocument();
doc.Load(Application.ExecutablePath + ".config");
XmlNode node = doc.SelectSingleNode(@"//add[@key='" + AppKey + "']");
XmlElement ele = (XmlElement)node;
if (node != null)
ele.SetAttribute("value", AppValue);
else
{
XmlElement xElem2;
xElem2 = doc.CreateElement("add");
xElem2.SetAttribute("key", AppKey);
xElem2.SetAttribute("value", AppValue);
node.AppendChild(xElem2);
}
doc.Save(Application.ExecutablePath + ".config");
}