Det virker stadig kun på mn computer. Over netværket giver det fejl. Koden ser sålees ud:
aspx:
<%@ Page language="c#" Codebehind="XPOpdateringerE.aspx.cs" AutoEventWireup="false" Inherits="New.XPOpdateringerE" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>DrectoryBrowser</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="
http://schemas.microsoft.com/intellisense/ie5"> </HEAD>
<body bgcolor="#e7e7ef">
<form id="Form1" method="post" runat="server">
<asp:table id="tblFileView" runat="server" Font-Names="Verdana" CellSpacing="0" CellPadding="1"
BorderColor="Gray" BorderWidth="1px" BorderStyle="Solid" GridLines="Both" Font-Size="XX-Small">
<asp:TableRow ForeColor="#000040" BackColor="#FFFFC0" Font-Bold="True">
<asp:TableCell Text="ItemName"></asp:TableCell>
<asp:TableCell Text="Creation DataTime"></asp:TableCell>
</asp:TableRow>
</asp:table>
</form>
</body>
</HTML>
cs:
using System;
using System.IO;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using New;
namespace New
{
/// <summary>
/// Summary description for WebForm1.
/// </summary>
public class XPOpdateringerE : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Table tblFileView;
private void Page_Load(object sender, System.EventArgs e)
{
//AddDirectoryView(Request.PhysicalApplicationPath);
if(CurrentPath == null)
CurrentPath = Request.PhysicalApplicationPath;
AddDirectoryView(CurrentPath);
}
// metode til at smide rækkerne ind i tabellen
//(sørger for at du bliver stående samme sted i filstrukturen, hvis du prøver at stikke næsen i et dir du ikke må kigge i - istedet for at fejle)
public void AddDirectoryView(string path)
{
try
{
// parent path
DirectoryInfo parent = Directory.GetParent(path);
if(parent != null)
AddItem(parent);
// først indsættes rækker for alle direktories i path
string[] items = Directory.GetDirectories(path);
foreach (string s in items)
{
AddItem(new DirectoryInfo(s));
}
// derefter rækker for alle filer
items = Directory.GetFiles(path);
foreach (string s in items)
{
AddItem(new FileInfo(s));
}
}
catch
{
string lp = LastPath;
CurrentPath = LastPath;
LastPath = lp;
Response.Redirect(Request.RawUrl);
}
}
// metode til at smide en enkelt række ind i tabellen
private void AddItem(FileSystemInfo itemInfo)
{
tblFileView.Rows.Add(CreateItemRow(itemInfo));
}
// metode til at danne en række
private TableRow CreateItemRow(FileSystemInfo itemInfo)
{
TableRow tr = new TableRow();
// lidt farveværk
if(itemInfo is DirectoryInfo)
tr.BackColor = Color.LightBlue;
// en linkbutton så man kan klikke på fil/dir navnet
LinkButton lbtn = new LinkButton();
lbtn.Click += new EventHandler(lbtn_Click);
lbtn.Text = itemInfo.Name;
lbtn.CommandName = itemInfo.GetType().Name;
lbtn.CommandArgument = itemInfo.FullName;
lbtn.Style.Add("text-decoration","none");
// ind med knappen
tr.Cells.Add(CreateItemCell(lbtn));
// ind med en ekstra oplysning
tr.Cells.Add(CreateItemCell(new LiteralControl(itemInfo.CreationTime.ToString())));
return tr;
}
// metode til at danne en enkelt celle
private TableCell CreateItemCell(Control content)
{
TableCell tc = new TableCell();
tc.Controls.Add(content);
return tc;
}
// håndtering af click-event fra knappen - CommandArgument skulle så gerne indeholde den fulde sti
private void lbtn_Click(object sender, EventArgs e)
{
if(((LinkButton)sender).CommandName == "DirectoryInfo")
{
LastPath = CurrentPath;
CurrentPath = ((LinkButton)sender).CommandArgument;
Response.Redirect(Request.RawUrl);
}
else if(((LinkButton)sender).CommandName == "FileInfo")
{
DatabaseFtpManagement instans=new DatabaseFtpManagement();
string filNavn=(string)((LinkButton)sender).CommandArgument;//=@"G:\Movies..."
instans.run(this, filNavn);
string newFile=filNavn.Remove(0, 3);//=Movies\...
string a="\\";
string b="/";
string endeligFil=newFile.Replace(a, b); //=/Movies../...
string endeligFil2="/"+endeligFil;
//System.Diagnostics.Debug.Write("efter erstatning: "+ endeligFil2);
//string endeligFil3="<a href=\"http:="+endeligFil2+"></a>";
//System.Diagnostics.Debug.Write("efter erstatning: "+ endeligFil3);
//Response.Redirect(filNavn);
Response.Redirect(endeligFil2);
}
}
// her returneres så startdiret fra før, hvis variablen ikke tidligere er sat
//=her gåes et skridt tilbage
//protected string CurrentStartPath
//{
// get{return (object)Session["CurrentPath"] != null ? (string)Session["CurrentPath"] : Request.PhysicalApplicationPath;}
// set{Session["CurrentPath"] = value;}
//}
protected string CurrentPath
{
get{return (object)Session["CurrentPath"] != null ? (string)Session["CurrentPath"] : @"E:XP-Opdateringer";}
set
{
if (value == @"E:\")
Session["CurrentPath"] = @"E:XP-Opdateringer";
else
Session["CurrentPath"] = value;
}
}
protected string LastPath
{
get{return (string)Session["LastPath"];}
set{Session["LastPath"] = value;}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void Repeater1_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
{
}
}
}