Autor Beitrag
new.Matrix
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Do 13.03.08 11:38 
Hallo Zusammen,

Ich habe folgendes Problem:

In einer Liste habe ich Bildname (bzw. Bildnummern) gespeichert. In einer Schleife möchte ich nun überprüfen ob dieses Bild schon existiert, nur gibt er mir immer zurück, dass das Bild existiert. Hier mein Code:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
_shopList[countRows].Haendler = Convert.ToInt16(res_HaendlerName[0]);
path.Append(@"images\" + _shopList[countRows].Haendler+".gif");
if (File.Exists(path.ToString()))
{
      Console.WriteLine("{0}The target already exists", path);
}
else
{

     Console.WriteLine("The target dosn't exists");
}


In der DebugConsole steht beim Compilieren:
images\208.gifThe target already exists
images\221.gifThe target already exists
images\337.gifThe target already exists
images\137.gifThe target already exists
images\221.gifThe target already exists
images\137.gifThe target already exists
images\61.gifThe target already exists
images\208.gifThe target already exists
images\262.gifThe target already exists
images\262.gifThe target already exists
images\174.gifThe target already exists
images\174.gifThe target already exists
images\71.gifThe target already exists
images\71.gifThe target already exists
images\312.gifThe target already exists
images\312.gifThe target already exists
images\459.gifThe target already exists
images\288.gifThe target already exists
images\94.gifThe target already exists
images\85.gifThe target already exists
images\94.gifThe target already exists
images\208.gifThe target already exists
images\221.gifThe target already exists
images\337.gifThe target already exists
images\137.gifThe target already exists
images\221.gifThe target already exists
images\137.gifThe target already exists
images\61.gifThe target already exists
images\208.gifThe target already exists
images\262.gifThe target already exists
images\262.gifThe target already exists
images\174.gifThe target already exists
images\174.gifThe target already exists
images\71.gifThe target already exists
images\71.gifThe target already exists
images\312.gifThe target already exists
images\312.gifThe target already exists
images\459.gifThe target already exists
images\288.gifThe target already exists
images\94.gifThe target already exists
images\85.gifThe target already exists
images\94.gifThe target already exists

Obwohl im Verzeichnis image nur das Bild 221.gif existiert. Weshalb das?


Moderiert von user profile iconChristian S.: Topic aus C# - Die Sprache verschoben am Do 13.03.2008 um 10:55
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 13.03.08 11:54 
Du benutzt einen relativen Pfad, eventuell liegt es daran. Benutze mal einen absoluten Pfad unter Verwendung von Application.StartupPath.

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
new.Matrix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Do 13.03.08 12:15 
Erstmals vielen Dank wieder einmal dir für deine prompte Antwort! Ist wirklich klasse!

Hmm.. Ich arbeite mt WPF, dabei muss ich zuerst, using System.Windows implementieren, damit ich Application zur Verfügung habe, aber auch dann habe ich keinen StartupPath, sondern nur die StartupUri zur Verfügung. Und diese gibt mir folgende Uri an: Application.Current.StartupUri: pack://application:,,,/Window1.xaml wobei dies ja nicht wirklich das Richige ist. Wo mache ich den Fehler?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 13.03.08 12:21 
Du kannst entweder die System.Windows.Forms.dll einbinden und das Application-Objekt von dort benutzen, oder hier habe ich folgendes gefunden:

ausblenden C#-Quelltext
1:
String appStartPath = System.IO.Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);					

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
new.Matrix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Do 13.03.08 14:54 
Besten Dank!

Soweit habe ichs nun hinbekommen, aber jetzt habe ioch folgendes Problem:

Der Pfad lautet:

D:\Eigene Dateien\Visual Studio 2008\Projects\WPF\v6\ControlPanel\ControlPanel\bin\Debug\images\94.gif

Der Ordner image(habe ich im SolutionExplorer->newFoldwe, Add Eisting items hinzugefügt) ist aber unter folgendem Pfad:


D:\Eigene Dateien\Visual Studio 2008\Projects\WPF\v6\ControlPanel\ControlPanel\bin\images\94.gif

Was schliesslich dazu führt das er der compiler die Bilder nicht findet. Wie kann ich das Lösen?
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: Do 13.03.08 15:05 
Hallo!

Da später, wenn das Programm eingesetzt werden soll, die Bilder ja im Unterordner des Programmes zu finden sein müssen, sollten sie das auch während des Debuggings. Ich würde die Bilder daher so, wie ich es Dir schonmal hier beschrieben habe, in Dein Projekt einbinden, damit sie in den Unterordner kopiert werden.

Grüße
Christian

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
new.Matrix Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 56



BeitragVerfasst: Do 13.03.08 16:41 
Danke dir vielmals!

Habe irgendwie den Part:

Zitat:


Eigenschaften "Build Action" auf "None" und "Copy to Output Directoy" auf "Copy if newer".



übersehen :?

Jetzt klappts!