|
File.Exists works on physical files. In an ASP.NET web application (or even an ASP web application, or many other web application frameworks), paths are virtual. They map to a physical path but not automatically.
To map a virtual path to a physical path in ASP.NET, use Server.MapPath or Page.MapPath depending on your context. If your code was in a page, for example, you would use:
if (File.Exists(MapPath("/path/to/file.aspx")))
In the future, please direct ASP.NET-related questions to the ASP.NET forum regardless of what language you're using. The ASP.NET forum is specifically for ASP.NET-related questions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
An issue to consider: asp.net runs (by default) under a user account on the local machine (the web server, that is.). Chances are good that this account does not have access to the files you are trying to reach on the network folder, so Exists() will always return false.
The only solution I've found if I REALLY need to access files across the network from within asp.net code is to impersonate. Since this is a little involved, I am not going to take up community bandwidth unless you are sure this is what you need to do.
It would make life much easier if you can get all the files onto the webserver. If you cannot, please post if you need details, I'll post an example.
Hope this helps,
Bill
|
|
|
|
|
Hello,
I want to develop a little Smart Device Application for my Pocket Pc with a little database. further when i developed the application i want to synchronise the database of the PocketPc with the database on my desktop. Does anybody have to these problems any code samples or literature and/or can give me further help?
thx
regards
|
|
|
|
|
Hi,
I've created an app which adds rows to a table, which I view in a DataGrid. But the application hangs after a while, especially if I move the window around. Does anyone know how to get around this problem. I'm using a thread that once a second adds a row to the table, and I think that the DataGrid or something surrounding it is not threadsafe. I am quite surprised that it is not threadsafe, but maybe there is something underneath it all that explains it.
I've put together a testcase where this is happening, see below.
Any pointers are welcome.
Regards
Tobias
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Threading;
namespace DataGridTest2
{
///
/// Summary description for Form1.
///
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
private System.Data.DataTable rLogDataTable = null;
private System.Data.DataSet rDataSet = null;
private DateTime rStartTimeStamp;
private int index = 0;
private Thread rResponseThread = null;
public Form1()
{
rStartTimeStamp = DateTime.Now;
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
createLogDataTable();
dataGrid1.SetDataBinding( rDataSet, "Log" );
rResponseThread = new Thread( new ThreadStart( this.responseThread ) );
rResponseThread.Start();
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
rResponseThread.Abort();
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.button1 = new System.Windows.Forms.Button();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.tabPage2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(32, 48);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(624, 568);
this.tabControl1.TabIndex = 0;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.button1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(616, 542);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
//
// tabPage2
//
this.tabPage2.Controls.Add(this.dataGrid1);
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Size = new System.Drawing.Size(616, 542);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
//
// button1
//
this.button1.Location = new System.Drawing.Point(104, 112);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(272, 120);
this.button1.TabIndex = 0;
this.button1.Text = "Add Item To Grid";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(16, 24);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(584, 496);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(688, 646);
this.Controls.Add(this.tabControl1);
this.Name = "Form1";
this.Text = "Form1";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.tabPage2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void button1_Click(object sender, System.EventArgs e)
{
DateTime rTmp = DateTime.Now;
TimeSpan rTimeDiff = rTmp - rStartTimeStamp;
this.addToLog( ""+(index++), "test", rTimeDiff );
}
private void addToLog( string sID, string sEvent, TimeSpan rTS )
{
DataRow myDataRow = rLogDataTable.NewRow();
myDataRow["ID"] = sID;
myDataRow["Event"] = sEvent;
myDataRow["TimeDiff"] = rTS;
rLogDataTable.Rows.Add(myDataRow);
}
private void createLogDataTable()
{
// Create a new DataTable.
rLogDataTable = new DataTable("Log");
// Declare variables for DataColumn and DataRow objects.
DataColumn myDataColumn;
// Create new DataColumn, set DataType, ColumnName and add to DataTable.
//
// The ID
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "ID";
myDataColumn.AutoIncrement = false;
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the Column to the DataColumnCollection.
rLogDataTable.Columns.Add(myDataColumn);
//
// The Event
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "Event";
myDataColumn.AutoIncrement = false;
myDataColumn.Caption = "ParentItem";
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the column to the table.
rLogDataTable.Columns.Add(myDataColumn);
//
// The Time-string
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.TimeSpan");
myDataColumn.ColumnName = "TimeDiff";
myDataColumn.AutoIncrement = false;
myDataColumn.Caption = "ParentItem";
myDataColumn.ReadOnly = false;
myDataColumn.Unique = false;
// Add the column to the table.
rLogDataTable.Columns.Add(myDataColumn);
// Instantiate the DataSet variable.
rDataSet = new DataSet();
// Add the new DataTable to the DataSet.
rDataSet.Tables.Add(rLogDataTable);
}
private void responseThread()
{
string sThreadName = "ResponsePollingThread";
Thread.CurrentThread.Name = sThreadName;
string sTmp = null;
string sSeparator = "\n*************************************\n";
bool found = false;
string searchstring = null;
try
{
while( true )
{
DateTime rTmp = DateTime.Now;
TimeSpan rTimeDiff = rTmp - rStartTimeStamp;
this.addToLog( ""+(index++), "thread", rTimeDiff );
Thread.Sleep( 1000 );
}
}
catch( Exception e )
{
// Console.WriteLine( "Exception in "+sThreadName+", exception; "+e );
Console.WriteLine( "Updater-thread ended." );
}
}
}
}
|
|
|
|
|
i dont think _any_ winforms controls are to be considered thread safe..
use .BeginInvoke or such to marshal teh calls into the main thread and manipulate teh controls there.
//Roger
|
|
|
|
|
Hi,
Now I've implemented a solution which seems to work fine.
This is what I needed to do:
1) Create a 'delegate' which had the same signature as my addToLog(...)-method.
public delegate void myDelegate( string id, string e, TimeSpan ts );
2) Modify the responseThread()-method so that it creates the delegate
myDelegate md = new myDelegate( addToLog );
3) Modify the responseThread()-method so that it calls (or more accurately invokes) the delegate with the appropriate arguments:
so the line that before said:
this.addToLog( ""+(index++), "thread", rTimeDiff );
Now says:
this.Invoke( md, new Object[] { ""+(index++), "thread", rTimeDiff } );
private void responseThread() <br />
{ <br />
string sThreadName = "ResponsePollingThread";<br />
Thread.CurrentThread.Name = sThreadName;<br />
string sTmp = null;<br />
string sSeparator = "\n*************************************\n";<br />
bool found = false;<br />
string searchstring = null;<br />
myDelegate md = new myDelegate( addToLog );<br />
try <br />
{<br />
while( true ) <br />
{<br />
DateTime rTmp = DateTime.Now;<br />
TimeSpan rTimeDiff = rTmp - rStartTimeStamp;<br />
this.Invoke( md, new Object[] { ""+(index++), "thread", rTimeDiff } );<br />
Thread.Sleep( 1000 );<br />
}<br />
}<br />
catch( Exception e ) <br />
{<br />
Console.WriteLine( "Updater-thread ended." );<br />
}<br />
}
|
|
|
|
|
Ok so here's my question:
Does anyone know how to make (in C# of course) a child window that has focus at the same time the parent form does *and* exists outside of the main parent form.
I don't want MDI because it requires the child form to sit inside of the main parent form. I know it's doable in the Windows environment since I have two programs that do this (Photoshop and Flash). Their tool palettes can be clicked on and they do not tear away focus from the main form on the desktop.
I suppose I can cheat and whenever someone clicks on a button inside of the toolpalette (i.e. the child form), call Focus() on the parent form. But like I say I know in the Windows environment it is possible to have both maintain focus. Since Photoshop and Flash both do it.
Does anyone know a way around this? Any help would of course be most valuable and appreciated.

|
|
|
|
|
Hello,I am trying to create <xsl:value-of select="....."> element(... means any string value) in a XML document.I used xmldocument.createElement("xsl:value-of select=\".... "); command.But it is not correct.how can I create xsl instructions in xml document with this method?Or should I try another way?Please help
|
|
|
|
|
Hi there,
I need to get the server time from a server which is located in canada.
Is there any possibility to do this with a direct call to the server without having anything else installed on the server.
I have admin rights on the server and so on.
let me know if you need anymore information 
|
|
|
|
|
I am working on an app that should open a logfile and then it should be possible to:
1. output the whole file as it is
2. reverse the output
3. filter the output
I am outputting to a richtextbox since I also want to highlight specific lines.
I have tried both using ArrayList and StringBuilder. The latter seems better but then it is not so easy to reverse. To add all text to the RichTextBox I use RTB.Text. I have also thought of outputting all to a temp file and use RTB.LoadFile instead.
The problem is that the logfiles can be quite huge, >5MB in extreme cases. This causes it to be very slow and I also encounter out-of-index problems in certain situations that I have not been able to pin down in the debugger.
Could anyone advice me on the best way to get a stable and not to slow solution (since I have to work through the whole file line by line to filter it will never be quick)?
Code extract:
try
{
StreamReader sr = File.OpenText(fileName);
string input = null;
//ArrayList myList = new ArrayList();
StringBuilder sb = new StringBuilder();
while ((input = sr.ReadLine()) != null)
{
if ( Filter or not )
{
Filtering of each line.
If condition met then
sb.Append(input);
//myList.Add(input);
}
}
else {
sb.Append(input);
//myList.Add(input);
//myList.TrimToSize();
}
}
sr.Close();
//myList.TrimToSize();
if ( checkBox4.Checked ) { //myList.Reverse(); }
richTextBox1.Clear();
/*
for (int i=0;i<myList.Count;i++)
{
sb.Append(myList[i].ToString() + "\n");
}
*/
richTextBox1.Text = sb.ToString();
}
catch (Exception e)
{ MessageBox.Show(e.ToString()); }
}
|
|
|
|
|
Obviously, you have to check each line in your file for your filtering condition.
You could use XML instead, for which the .NET Framework has built-in support.
This is not a valid xml file, but you might understand what I am after:
<logfile>
<logdate="22.01.2005"/>
<logdate="23.01.2005">
<errors>
<entry>
....
</entry>
<entry>
....
</entry>
....
....
</errors>
<warnings>
....
....
</warnings>
</logdate>
<logdate="....">
....
</logdate>
</logfile>
Thus, by organizing your data you will be able to find things faster.
Additionally, this already is tree-shaped, so you can easily include it into
a tree view or something and show error-specific details in a rich-text box.
Another way would be to do some organizing yourself. you could have different logfiles for categories, so when the user filters for one category, you simply have to load a file.
Also, filtering is much easier if you perform these operations in RAM, not on disk (by loading each line seperatly instead of buffering first, then filtering later).
Cheers
Sebastian
|
|
|
|
|
Thanks for your answer but unfortunately I have no control of the logfile. It's because it's huge and diifcult to read I'd like to build my own logfile reader.
What I need most I think is a tip on how to reverse output using StringBuilder. Otherwise I do thing StringBuilder is the way to go.
|
|
|
|
|
HI~
I am writing C# and use the CF to write mobile application.
I use the input panel control.
The input panel control provide "EnabledChanged" event handler
I write something like this:
inputPanel1.EnabledChange += new System.EventHandler(this.whenChange);
And then I write:
if (inputPanel1.Enable)
{
inputPanel1.Enable = false;
}
This of course will cause the program execute the "whenChanged(Object sender, SystemArgs e)".
The expected result is happened in the emulator. However, testing the program in a real device cause error. The event handler does not execute. That means the "whenChange(..)" method does not execute.
Why this happen?
Thanks
p.s , the real device has installed .NET CF SP2.
|
|
|
|
|
Hello All,
It is possible with C#? If not, anyway to define my own event
accessor methods as in MC++?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
hi,
It is possible with C#?
what is possible with C# ?
**************************
S r e e j i t h N a i r
**************************
|
|
|
|
|
sreejith ss nair wrote:
what is possible with C# ?
Hmmmm, the claim is that it is a better VB, may be not the current version.
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
i use directdraw load a bmpfile to a surface,and i want circumgyrate the bmpfile some angle in my program, how to do it? please help me, thanks.
|
|
|
|
|
If you mean draw it rotated then the answer is that you can't. DirectDraw does not support rotation. You'll have to manually rotate it (using GDI+ for example - see the Graphics class and RotateTransform() in it) and make a new bitmap.
|
|
|
|
|
Hello All,
Is there any equivalent to the /fx C++ compiler option
for C#?
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
|
If I could get access to the codes generated for the delegates - hope I could find a way out
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
There was a program called ILDASM that could disassemble a .Net program into IL. Perhaps that might help you? (But chances are delegates are still delegates even at the IL layer)
|
|
|
|
|
Thanks for the support.
EssOEss wrote:
ILDASM
As a C# programmer I should know ILDASM
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|
Hello,
What is the best way to have something like this?
protected delegate string CalculationDelegate(int count);
protected delegate string CalculationDelegate(double count);
Best regards,
Paul.
Jesus Christ is LOVE! Please tell somebody.
|
|
|
|
|