有a.aspx,b.aspx两个页面
a.aspx.cs里我写了public static string str()函数,我想在
b.aspx.cs里调用a.aspx.cs中的str函数,如何调用!
注:两页同属一目录
谢谢!
a.aspx.cs里我写了public static string str()函数,我想在
b.aspx.cs里调用a.aspx.cs中的str函数,如何调用!
注:两页同属一目录
谢谢!
using System.Text;
using System.IO;
using System.Net;
using System.Data;
using System.Data.SqlClient;namespace WrCms
{
/// <summary>
/// TempPublic 的摘要说明。
/// </summary>
public class FileAct
{
public FileAct()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
#region 获取内容显示页打开地址
static public string GetUrl(object id,int t)
{
string wwwurl=DB.GetSysConfig()[3].Trim();
string wwwpath=DB.GetSysConfig()[0].Trim();
string url="";
string classid="";
string addtime; DataRow row = null;
switch(t)
{
case 1:
row = DB.Article_Show(id);
break;
case 3:
row = DB.Down_Show(id);
break;
case 4:
row = DB.News_Show(id);
break;
case 5:
row = DB.Flash_Show(id);
break;
}
if(row != null)
{
classid = row["classid"].ToString();
addtime = row["addtime"].ToString();
}
else
return url;
row = DB.Temp_Show(classid,1);
if(row != null)
{
string[] date=addtime.Substring(0,addtime.IndexOf(" ",0,addtime.Length)).Split('-');
url = row["savepath"].ToString();
url = wwwurl+url.Replace("{year}",date[0]).Replace("{month}",date[1]).Replace("{day}",date[2]).Replace("{id}",id.ToString());
}
return url;
}
#endregion
#region //下载文件
static public void DownloadFile(string address,string filename)
{
WebClient wc = new WebClient();
try
{
wc.DownloadFile(address,filename);
}
catch(Exception ex)
{
throw new ApplicationException(ex.ToString());
}
wc.Dispose();
}
#endregion
#region //生成目录
static public void CreateDirectory(string path)
{
try
{
if(!Directory.Exists(path))
Directory.CreateDirectory(path);
}
catch(Exception ex)
{
throw new ApplicationException(ex.ToString());
}
}
#endregion
#region 删除文件
static public void DelFileUrl(string url)
{
string wwwurl=DB.GetSysConfig()[3].Trim();
string wwwpath=DB.GetSysConfig()[0].Trim();
try
{
System.IO.File.Delete(url.Replace(wwwurl,wwwpath).Replace("/","\\"));
}
catch(Exception ex)
{
throw new ApplicationException(ex.ToString());
}
}
#endregion
#region //生成显示页
static public void contentSc(string id,object classid,int t)
{
try
{
string wwwpath=DB.GetSysConfig()[0].Trim();
string temppath=DB.GetSysConfig()[1].Trim();
string tempurl=DB.GetSysConfig()[4].Trim();
string wwwurl=DB.GetSysConfig()[3].Trim(); DataRow row = DB.Temp_Show(classid,1);
string tmppath=row["temppath"].ToString().Trim();
//tmppath = tmppath.Substring(0,tmppath.LastIndexOf("/"));
string hometxt=tmppath.Replace("date/show.aspx","{year}-{month}/{day}_{id}.html");
hometxt=hometxt.Replace(".aspx",".htm"); WebClient Client = new WebClient();
Stream stm = Client.OpenRead(tempurl+tmppath+"?id="+id);
StreamReader sr = new StreamReader(stm, Encoding.GetEncoding("gb2312"));
string content= sr.ReadToEnd(); row=null;
switch(t)
{
case 1:
row=DB.Article_Show(id);
break;
case 3:
row=DB.Down_Show(id);
break;
case 4:
row=DB.News_Show(id);
break;
case 5:
row = DB.Flash_Show(id);
break;
}
if(row!=null && row["ispost"].ToString()=="True")
{
string[] date=row["addtime"].ToString().Trim().Substring(0,row["addtime"].ToString().Trim().IndexOf(" ",0,row["addtime"].ToString().Trim().Length)).Split('-');
string filepath=hometxt.Replace("{year}",date[0]).Replace("{month}",date[1]).Replace("{day}",date[2]).Replace("{id}",id);
string[] wfile=filepath.Split('/');
string classpath="";
for(int j=0;j<wfile.Length-1;j++)
{
classpath+=wfile[j].Trim();
if(!Directory.Exists(wwwpath+classpath))
Directory.CreateDirectory(wwwpath+classpath);
classpath+="\\";
}
DB.Temp_Save(classid,1,hometxt);
StreamWriter writer=new StreamWriter(wwwpath+filepath.Replace("/","\\"),false,Encoding.GetEncoding("gb2312"));
writer.WriteLine(content);
writer.Close();
}
}
catch(Exception ex)
{
throw new ApplicationException(ex.ToString());
}
}
#endregion
}
}