public static string Replease(string originalStr, string repleasStr, string newStr)
{
int pos = originalStr.IndexOf(repleasStr);
int len = repleasStr.Length;
if (pos != -1)
{
string strLeft = originalStr.Substring(0, pos);
string strRight = originalStr.Substring(pos + len);
return strLeft + newStr + strRight;
}
else
return originalStr;
}
2009/04/02
c# 將string array轉成文字
public static string[] StringToLines(string inString)
{
string[] org = inString.Split('\n');
int count = org.Length - 1;
string[] outString = new string[count];
try
{
for (int i = 0; i < count; i++)
{
if (org[i].IndexOf('\r') == -1)
org[i] = org[i];
else
org[i] = org[i].Remove(org[i].IndexOf('\r'));
//int j = org[i].IndexOf('\r');
outString[i] = org[i];
}
}
catch
{
return null;
}
return outString;
}
{
string[] org = inString.Split('\n');
int count = org.Length - 1;
string[] outString = new string[count];
try
{
for (int i = 0; i < count; i++)
{
if (org[i].IndexOf('\r') == -1)
org[i] = org[i];
else
org[i] = org[i].Remove(org[i].IndexOf('\r'));
//int j = org[i].IndexOf('\r');
outString[i] = org[i];
}
}
catch
{
return null;
}
return outString;
}
c# 建立空的StreamReader
public static StreamReader GetEmptyStreamReader()
{
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write("");
sw.Flush();
StreamReader sr = new StreamReader(ms);
return sr;
}
{
MemoryStream ms = new MemoryStream();
StreamWriter sw = new StreamWriter(ms);
sw.Write("");
sw.Flush();
StreamReader sr = new StreamReader(ms);
return sr;
}
c# 取得檔案列表
// Dir folder
public bool FileList(string folderName)
{
try
{
DirectoryInfo dirinfo = new DirectoryInfo(folderName);
FileInfo[] sortList = dirinfo.GetFiles();
string[] dirList = new string[sortList.Length];
string[] fileName = new string[sortList.Length];
for (int i = 0; i < sortList.Length; i++)
{
dirList[i] = sortList[i].Name.ToString();
fileName[i] = sortList[i].FullName.ToString();
}
FullFileName = fileName;
FileName = dirList;
return true;
}
catch (Exception ex)
{
_errorMessage = ex.ToString();
return false;
}
}
public bool FileList(string folderName)
{
try
{
DirectoryInfo dirinfo = new DirectoryInfo(folderName);
FileInfo[] sortList = dirinfo.GetFiles();
string[] dirList = new string[sortList.Length];
string[] fileName = new string[sortList.Length];
for (int i = 0; i < sortList.Length; i++)
{
dirList[i] = sortList[i].Name.ToString();
fileName[i] = sortList[i].FullName.ToString();
}
FullFileName = fileName;
FileName = dirList;
return true;
}
catch (Exception ex)
{
_errorMessage = ex.ToString();
return false;
}
}
C# 取得文字檔中的內容
// Get file content string
public string FileContent(string fileName)
{
StreamReader stmRdr = new StreamReader(fileName);
string line = stmRdr.ReadLine();
string sLine = null;
while (line != null)
{
if (line.Length != 0)
sLine = sLine + line + '\n';
line = stmRdr.ReadLine();
}
stmRdr.Close();
return sLine;
}
public string FileContent(string fileName)
{
StreamReader stmRdr = new StreamReader(fileName);
string line = stmRdr.ReadLine();
string sLine = null;
while (line != null)
{
if (line.Length != 0)
sLine = sLine + line + '\n';
line = stmRdr.ReadLine();
}
stmRdr.Close();
return sLine;
}
c# FTP的使用 -- 修改檔名(mv)
// Reanme file or remove file
public bool FtpRename()
{
if (this.InputValidation())
{
try
{
Uri UriFtpMove = new Uri("ftp://" + serverhost + ":" + serverport + dirpath + remotefile);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UriFtpMove);
request.Method = WebRequestMethods.Ftp.Rename;
request.RenameTo = renamefile;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
returnmsg = response.BannerMessage;
returncode = response.StatusCode.ToString();
return true;
}
catch (Exception ex)
{
returnmsg = ex.ToString();
returncode = "0";
return false;
}
}
else
{
throw new ArgumentException(returnmsg);
}
}
public bool FtpRename()
{
if (this.InputValidation())
{
try
{
Uri UriFtpMove = new Uri("ftp://" + serverhost + ":" + serverport + dirpath + remotefile);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UriFtpMove);
request.Method = WebRequestMethods.Ftp.Rename;
request.RenameTo = renamefile;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
returnmsg = response.BannerMessage;
returncode = response.StatusCode.ToString();
return true;
}
catch (Exception ex)
{
returnmsg = ex.ToString();
returncode = "0";
return false;
}
}
else
{
throw new ArgumentException(returnmsg);
}
}
c# FTP的使用 -- 取得FTP Server的檔案列表(ls)
// Get file list
public string[] FtpDir()
{
string Result = "";
if (this.InputValidation())
{
try
{
Uri UriFtpDir = new Uri("ftp://" + serverhost + ":" + serverport + dirpath + filter);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UriFtpDir);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
StreamReader MyStreamReader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
returnmsg = response.BannerMessage;
returncode = response.StatusCode.ToString();
Result = MyStreamReader.ReadToEnd();
}
catch (Exception ex)
{
returnmsg = ex.ToString();
returncode = "0";
throw new ArgumentException(returnmsg);
}
}
else
{
throw new ArgumentException(returnmsg);
}
return Strings.StringToLines(Result);
}
public string[] FtpDir()
{
string Result = "";
if (this.InputValidation())
{
try
{
Uri UriFtpDir = new Uri("ftp://" + serverhost + ":" + serverport + dirpath + filter);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UriFtpDir);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
StreamReader MyStreamReader = new StreamReader(response.GetResponseStream(), System.Text.Encoding.Default);
returnmsg = response.BannerMessage;
returncode = response.StatusCode.ToString();
Result = MyStreamReader.ReadToEnd();
}
catch (Exception ex)
{
returnmsg = ex.ToString();
returncode = "0";
throw new ArgumentException(returnmsg);
}
}
else
{
throw new ArgumentException(returnmsg);
}
return Strings.StringToLines(Result);
}
c# FTP的使用 -- 取得FTP Server的檔案(get)
// Get ftp file content
//public StreamReader FtpGet()
public bool FtpGet()
{
FileStream fileStream = null;
Stream responseStream = null;
if (this.InputValidation())
{
try
{
Uri UriFtpGet = new Uri("ftp://" + serverhost + ":" + serverport + dirpath + remotefile);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UriFtpGet);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
returnmsg = response.BannerMessage;
returncode = response.StatusCode.ToString();
// Write into file
if (localfile == null)
localfile = Path.GetFileName(request.RequestUri.AbsolutePath);
fileStream = File.Create(localPath + @"\" + localfile);
byte[] buffer = new byte[1024];
int bytesRead;
while (true)
{
bytesRead = responseStream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
fileStream.Write(buffer, 0, bytesRead);
}
responseStream.Close();
fileStream.Close();
return true;
}
catch (Exception ex)
{
returnmsg = ex.ToString();
returncode = "0";
return false;
}
}
else
{
throw new ArgumentException(returnmsg);
}
}
//public StreamReader FtpGet()
public bool FtpGet()
{
FileStream fileStream = null;
Stream responseStream = null;
if (this.InputValidation())
{
try
{
Uri UriFtpGet = new Uri("ftp://" + serverhost + ":" + serverport + dirpath + remotefile);
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(UriFtpGet);
request.Method = WebRequestMethods.Ftp.DownloadFile;
request.Credentials = new NetworkCredential(username, password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();
returnmsg = response.BannerMessage;
returncode = response.StatusCode.ToString();
// Write into file
if (localfile == null)
localfile = Path.GetFileName(request.RequestUri.AbsolutePath);
fileStream = File.Create(localPath + @"\" + localfile);
byte[] buffer = new byte[1024];
int bytesRead;
while (true)
{
bytesRead = responseStream.Read(buffer, 0, buffer.Length);
if (bytesRead == 0)
break;
fileStream.Write(buffer, 0, bytesRead);
}
responseStream.Close();
fileStream.Close();
return true;
}
catch (Exception ex)
{
returnmsg = ex.ToString();
returncode = "0";
return false;
}
}
else
{
throw new ArgumentException(returnmsg);
}
}
2009/03/31
ora-12154 tns could not resolve the connect identifier specified
今天裝了二次Oracle Client,第一次失敗,第二次成功
接著我設定組態,也成功連結到資料庫
但在使用SQL/Plus以及 PL/SQL的時候出現:
ora-12154 tns could not resolve the connect identifier specified
上網搜尋後,也有很多人遇到相同的問題,我依方法進行確認
發現我環境變數path是:
d:\oracle11g\client_1\bin;d:\oracle11g\client_2\bin;...
修改成
d:\oracle11g\client_1;d:\oracle11g\client_1\bin;...
就可以使用SQL/Plus 和 PL/SQL 了
接著我設定組態,也成功連結到資料庫
但在使用SQL/Plus以及 PL/SQL的時候出現:
ora-12154 tns could not resolve the connect identifier specified
上網搜尋後,也有很多人遇到相同的問題,我依方法進行確認
發現我環境變數path是:
d:\oracle11g\client_1\bin;d:\oracle11g\client_2\bin;...
修改成
d:\oracle11g\client_1;d:\oracle11g\client_1\bin;...
就可以使用SQL/Plus 和 PL/SQL 了
訂閱:
文章 (Atom)