Encoding myEncoding = Encoding.GetEncoding("UTF-8");
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://localhost:57694/Default.aspx");
req.Method = "GET";
using (WebResponse wr = req.GetResponse())
{
using (StreamReader myStreamReader = new StreamReader(wr.GetResponseStream(), myEncoding))
{
string data = myStreamReader.ReadToEnd();
Console.WriteLine("data:" + data.Split('\n')[0]);
}
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

//查詢資料夾目錄下所有檔案名稱
public void DirSearch(string sDir)
{
try
{
//先找出所有目錄
foreach (string d in Directory.GetDirectories(sDir))
{
//先針對目前目路的檔案做處理
foreach (string f in Directory.GetFiles(d))
{
Console.WriteLine(f);
}
//此目錄處理完再針對每個子目錄做處理
DirSearch(d);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
}
/* Form 查詢資料夾內容清單
String[] FileCollection;
String FilePath = "F:\\Uploads";
FileInfo theFileInfo;
FileCollection = Directory.GetFiles(FilePath, "*.txt");
for(int i = 0 ; i < FileCollection.Length ; i++)
{
theFileInfo = new FileInfo(FileCollection[i]);
Response.Write(theFileInfo.Name.ToString());
}
*/

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

//紀錄Log方法
private void Log(string msg)
{
System.IO.File.AppendAllText(AppDomain.CurrentDomain.BaseDirectory + @"\log.txt", DateTime.Now + "\t" + msg + Environment.NewLine);
}
//.net 2.0 Log記錄寫法
string path = AppDomain.CurrentDomain.BaseDirectory + @"\log.txt";
using (StreamWriter sw = File.AppendText(path)) 
{                    
    sw.WriteLine(DateTime.Now.ToString() + "  " + ex.ToString());
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

//畫面POSTBACK後定位在刷新前的位置
//在web.config 的 中加上下列語法即可

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

//Console.Write("\nPlease enter the URL to post data to : ");
string uriString = "http://localhost:62711/Default.aspx";
// Create a new WebClient instance.
WebClient myWebClient = new WebClient();
// Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
NameValueCollection myNameValueCollection = new NameValueCollection();
Console.WriteLine("Please enter the following parameters to be posted to the URI");
Console.Write("Name:");
string name = Console.ReadLine();
Console.Write("Age:");
string age = Console.ReadLine();
Console.Write("Address:");
string address = Console.ReadLine();
// Add necessary parameter/value pairs to the name/value container.
myNameValueCollection.Add("Name", name);
myNameValueCollection.Add("Address", address);
myNameValueCollection.Add("Age", age);
Console.WriteLine("\nUploading to {0} ...", uriString);
// Upload the NameValueCollection.
byte[] responseArray = myWebClient.UploadValues(uriString, "POST", myNameValueCollection);
// Decode and display the response.
Console.WriteLine("\nResponse received was :\n{0}", Encoding.ASCII.GetString(responseArray));

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

private DataSet GetDBData(string DBLink,string Sql,string TableName)
{
SqlConnection Conn = new SqlConnection(DBLink);
SqlDataAdapter da = new SqlDataAdapter(Sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds, TableName);
return ds;
}
private void DataControl(string DBLink,string Sql)
{
SqlConnection Conn = new SqlConnection(DBLink);
Conn.Open();
SqlCommand command = new SqlCommand(Sql,Conn);
command.ExecuteNonQuery();
Conn.Dispose();
Conn.Close();
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

private DataSet GetDBData(string DBLink,string Sql,string TableName)
{
SqlConnection Conn = new SqlConnection(DBLink);
SqlDataAdapter da = new SqlDataAdapter(Sql, Conn);
DataSet ds = new DataSet();
da.Fill(ds, TableName);
return ds;
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

string str = Strings.StrConv(textBox1.Text, VbStrConv.Narrow, 0).ToLower().Trim().ToUpper();//全形轉半形 英文大寫
MessageBox.Show(str);

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

if (e.Button == MouseButtons.Right)
{
Point p = MousePosition;//取得滑鼠位置
contextMenuStrip1.Show(p);//顯示右鍵選單
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

Form 或是 主控台應用程式可在App.config內加上
WebForm則是在Web.config內加上

<system.net>
  <defaultProxy useDefaultCredentials="true"></defaultProxy>
</system.net>

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

private string GetHttpTxt(string strUrl)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(strUrl);
HttpWebResponse webresponse = (HttpWebResponse)request.GetResponse();
StreamReader streamReader = new StreamReader(webresponse.GetResponseStream(), Encoding.UTF8);
webresponse.Close();
return streamReader.ReadToEnd();
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

記錄發送Mail的功能:
MailMessage Msg = new MailMessage();
Msg.From = new MailAddress("寄件者");
Msg.To.Add("收件者");
Msg.To.Add("收件者");
Msg.CC.Add("副本收件者");
Msg.Bcc.Add("密件副本");
Msg.Subject = "Test Mail";//標題
Msg.Body = "content test!!";//內文
Msg.SubjectEncoding = Encoding.UTF8;
Msg.BodyEncoding = Encoding.UTF8;//編碼
Msg.IsBodyHtml = true;//是否以html顯示
string filePath = @"D:\test.pdf"; //要附加的檔案
Attachment attachment1 = new Attachment(filePath);
attachment1.Name = System.IO.Path.GetFileName(filePath);
attachment1.NameEncoding = Encoding.GetEncoding("utf-8");
attachment1.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;//編碼
attachment1.ContentDisposition.Inline = true;
attachment1.ContentDisposition.DispositionType = System.Net.Mime.DispositionTypeNames.Inline;
Msg.Attachments.Add(attachment1);
SmtpClient smtp = new SmtpClient("SMTP位置");
smtp.EnableSsl = true;//是否開啟SSL連線
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.Credentials = new NetworkCredential("帳號","密碼");
SmtpClient smtp = new SmtpClient(WebConfigurationManager.ConnectionStrings["webconfig紀錄之連線資訊"].ConnectionString);
try
{
smtp.Send(Msg);
attachment1.Dispose();
Msg.Dispose();
}
catch (Exception ex)
{
Response.Write(ex.ToString());
}

芭樂養樂多 發表在 痞客邦 留言(0) 人氣()

1 2
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。