一.js读取文件示例:
var Arr=new Array(); try { var fso=new ActiveXObject("scripting.filesystemobject_0418s"); var txtstream=fso.openTextFile('c://data.txt'); var txt=''; while(!txtstream.atEndOfLine) { Arr.push(txtstream.readLine()); } txtstream.close(); txtstream=null; fso=null; } catch(e){alert(e);} for(var i=0;i<Arr.length;i++) alert(Arr[i]);
data.txt 1 2 3 4 5 6
二.通用的类文件:
//*************************************通用函数类************************************
using System; using System.Data; using System.Configuration; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.IO;
namespace faxapp.common { public class commonfunction { //***********************************文件写入函数************************************** public static int buildDatafile(string fp,string[] content) { try { if (!File.Exists(fp)) { /* StreamWriter SW = File.CreateText(fp); for(int i=0;i<content.Length;i++) { SW.WriteLine(content[i]); } SW.Flush(); SW.Close()*/ File.WriteAllLines(fp, content); } return 0; } catch (Exception) {
return 1; } } //******************************文件删除函数********************************** public static int delDatafile(string fp) { try { File.Delete(fp); return 0; } catch (Exception) { return 1; } } //*******************************文字截断加……函数******************************* public static string cutStr(string str, int num) { if ((str.Length) > num) { str = " " + str.Substring(0, num) + "..."; return str; } else { return str; } }
//********************************字符串断开截取函数*********************************
//Mondify By LiFuyun //******* para :参数; 0则返回未处理的字符串数组;1返回传真号码数组;2返回人名数组;3返回传真格式数组******* public static string[] getstringlist(string content, int para) { string[] stringtotal; string[] stringno; string[] stringname; string[] stringfax; stringtotal=content.Split(';'); stringno = content.Split(';'); stringname = content.Split(';'); stringfax = content.Split(';'); int namelen; for (int i = 0; i < stringtotal.Length; i++) { if ((stringtotal[i].LastIndexOf(">") == -1) || stringtotal[i].IndexOf("<") == -1 || stringtotal[i].IndexOf("<")!=0) { stringname[i] = stringtotal[i]; stringno[i] = stringtotal[i]; stringfax[i] = stringno[i]; }else { namelen=stringtotal[i].LastIndexOf(">")-1; stringname[i]=stringtotal[i].Substring(1, namelen); stringno[i] = stringtotal[i].Substring(namelen + 2); stringfax[i] = stringno[i] + " " + stringname[i]; }
}
if (para == 0) { return stringtotal;
} else if (para == 1) { return stringno;
} else if (para == 2) { return stringname;
} else { return stringfax;
} } //**********************************asp。net弹出窗口函数,需要定义label控件*************************** public static string AlertMsg(string str) { return "<script>alert('" + str + "');</script>"; } } }