|
Yes, but try it, it still does not draw over the top of a picturebox, only behind it.
I think Christian is right tho, its kind of pointless. I just wanted to know if it was possible to stop the picturebox re-rendering itself.
|
|
|
|
|
// Make sure a duplicate file doesn’t exist. If it does, keep on appending an incremental numeric until it is unique
string sFilename = System.IO.Path.GetFileName(myFile.FileName);
string ans;
while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename)))
{
Console.Write("Do you want to overwrite? (Yes/No)");
ans = Console.ReadLine();
Console.WriteLine("");
}
lblOutput.Text = "File already existed. A duplicate file has been created";
the logic is upload file -> if file exists -> prompt for user input -> if yes -> overwrite -> if no prompt for user input for new file name
the code is not finished.. but am i on the right path??
|
|
|
|
|
Seems a bit lost to me
1 - you're using server.mappath, but you're writing to the console, is this a server application or not ?
2 - sSavePath + sFilename, why not use Path.Combine ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
1.sorry but what do you mean by server application?
i'm doing asp.net c#.. images upload
2. oh path.combine works too? oh so ty lol
|
|
|
|
|
OK, then this is a disaster. Your console code plainly is not going to work on a website, now is it ?
If you asked in the right forum, I'd have known for sure this was ASP.NET. If the code stood any chance of working, I may have figured it out. C# code runs on te server, not the client.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi
I want to create wrapper class dynamically. so i try to execute the command window programmatically. but i dont know how i can set the argument "TLBIMP compadd.dll \out:comprcw.dll". can anyone please tell me?
thanks
sri
|
|
|
|
|
You want to pass parameters to a process? Create a Process instance and set Arguments and FileName of its StartInfo property.
Cheers,
Vikram.
The hands that help are holier than the lips that pray.
|
|
|
|
|
I see a lot of VBscripts that map printers from a network drive/print server. My question is if this is possible with C#. I am more familiar with C# and not VB. At work we want to add a logon script (or have a console app pop up and automatically do this) and we want it to map all the network printers from our print server on the users computer (at each login).
I see how to manually map the printers with VBscript but the problem with this is if we delete a printer or rename it then we have to change the script.
If we have it delete the currently mapped printers and remap all the printers from the print server then we wouldn't have to worry about it. So can this be done with C# or is this a VBscript thing? I have asked this question in the VB form about doing it in VB but now I'm asking here to see if it is possible to do it with C# in a console app or something.
|
|
|
|
|
Yes there is. but it won't be a c# script or anything like that.
this can be done using visual studio 2005 or 2008. add a reference to your project "IWshRuntimeLibrary" it is a .COM library from a dll.
using IWshRuntimeLibrary;
public class x;
{
private void mapPrinter();
{
WshNetwork oNet = new WshNetwork();
oNet.AddWindowsPrinterConnection"\\\\SERVER\\printerName", "HPLJ4100", "\\\\SERVER\\printerName");
oNet.SetDefaultPrinter("\\\\SERVER\\printerName");
}
}
I hope this helps with this kind of project/s.
|
|
|
|
|
Hi,
I am trying to create a new log file in my exe folder through StreamWriter class, but I am getting the following exception. I have full access to the folder, but dont know why I am getting this.
My OS is Vista. Any quick help will be appreciated.
{System.UnauthorizedAccessException: Access to the path 'C:\Users\mah\Documents\Visual Studio 2005\Projects\sampleproj\bin\Debug' is denied.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter.CreateFile(String path, Boolean append)
at System.IO.StreamWriter..ctor(String path, Boolean append, Encoding encoding, Int32 bufferSize)
Thanks.
|
|
|
|
|
Vista does that, but in this case, could it be that the file is already open ?
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
no, file is not open..actually i am trying to create a new file here..
but anyway thanks for the reply..I got the solution for this, If I dont specify the path to the streamwriter, by deafult its creating the file in the debug directory..that is what I want.. But the weird thing is if I specify the path explicity then its raising the above error..
|
|
|
|
|
I have a lot of debugging statements in my code, and I want to compile most of them away in a release build. Is there any easier way to do this besides surrounding each one with #if DEBUG...?
An alternative solution would be to create a single method called Debug() which has the preprocessor statement inside of it. But this would involve refactoring a lot of code and would still involve a method invocation (albeit an empty one).
Any ideas?
|
|
|
|
|
Those are your two options, sorry
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
>>would still involve a method invocation (albeit an empty one).
You can mark the refactored code with the "ConditionalAttribute"
eg:
[Conditional("Debug")]
public void DoStuff()
{
}
This lets the compiler know that it should only _emit calls to that method if we are in debug mode_
So the method will still be present in release mode, but no calls to it will be present in the IL code.
(And if your debug statements are output stuff only. then just use "Debug.WriteLine(text)" , those will also be removed in release mode)
|
|
|
|
|
Hello, I am trying to write an application that will be able to manage an attendance list. It will talk back to a database and any updates made to the attendance list, will update the database.
So basically, there are students and classes.
each class has students.
I want to be able to maintain a list of students and a list of classes.
How should I go about doing this?
I am thinking of having the classes:
student - defines a student object
class - defines a class object
- list<student>
studentList - contains a list of ALL students
- list<student>
classList - contains a list of ALL classes
- list<class>
I would like to retrieve the student list of a particular class where should the method for this go?
Should it go in classList? maybe getStudents(int classID)
or class? just getstudents()?
i want to also be able to add students to a particular class from studentList.
where should the addStudentToClass method go? in the class or in the classList?
If it belongs in class, how do you get access to the studentList? do I have to pass the studentList as a variable through the constructor when i create the class? I know I can do it by making the studentList a static class then i can access the method by students.Add(studentList.GetStudentByID(int studentID))?
I would appreciate it greatly if someone could explain the levels of access and what classes should be able to access what by using the scenario above.
Thank you,
Kind Regards,
Mike </class></student></student>
|
|
|
|
|
Recommendations:
1) Don't use "class" for a class name... really don't. use "Course" or something appropriate. Never use keywords as class names or in parts of class names.
2) If it has to do with the class directly, then put it into that class. i.e. I'd put public static GetStudent() into the Student class.
3) Remember the "has-a" and "is-a" relationship. Curriculum has Courses. Courses have Students. I don't think you have a problem that requires inheritance here, so don't worry about the "is-a" relationship.
4) When you have problems getting started, it helps greatly to do the UML, even if it's sloppy who cares as long as you get a better understanding of the problem. Use a pencil and paper, don't worry about visio or other fancy tools. Pencils are twice as fast as visio - easy.
5) I presume that this is a student assignment? I'll give you a hint here, what you have is a nested problem, if you solve the Course/Students relationship, then you solved the Curriculum/Courses relationship.
Curriculum
-Courses
+Add(Course)
+Remove(Course)
+this[index]
Course
-Students
+Add(Student)
+Remove(Student)
+this[index]
+GetCourse(fromDB)
Student
-StudentInfo() //Info that I'm not going to go through.
+GetStudent(fromDB)
Scott P
“It is practically impossible to teach good programming to students that have had a prior exposure to BASIC: as potential programmers they are mentally mutilated beyond hope of regeneration.”
-Edsger Dijkstra
|
|
|
|
|
Hi, can anyone tell me what the ?? operator is for in C# ?
Thanks
|
|
|
|
|
It's a conditional statement where if the left hand side of the expression is non-null then it is returned, otherwise the right hand side is returned.
ex:
string value = GetSomeValue();
string result = null;
if (value == null)
{
result = "value is null";
}
else
{
result = value;
}
is the same as
string value = GetSomeValue();
string result = value ?? "value is null";
MSDN[^]
|
|
|
|
|
|
Hello
I have created my own event and delegate, they look like this:
public delegate Answer delegateCallResponse(Request req);
public event delegateCallResponse eventCallResponse;
the Request and Answer is 2 struct which contain a few strings/ints.
I got a method to handle the event, which look like
public Answer ans = new Answer();
private Answer OnEvent(Request req) {
FillRequest(req);
while (!ans.filled) { Thread.Sleep(1000); }
return this.ans; }
the ans.filled is a bool indication whether the information is filled or not.
My problem is that the Answer can take a while to get filled and the code as it is now, will make the mainthread sleep thus making the GUI unavailable for some time.
Is there a way to run the event in a thread? or just another way to make it wait than use the while function?
//QzRz
|
|
|
|
|
Use an Asynchronous method call to run FillRequest : Asynchronous Method Invocation[^]
then instead of looping waiting for ans.filled to be true you can set up a callback for when the function finishes.
|
|
|
|
|
If your event is in a class, you can create a method in that class that invokes the event asynchronously. Specifically, you can do:
<br />
ThreadPool.QueueUserWorkItem( delegate { <br />
if(eventCallResponse != null) {<br />
eventCallResponse(req)<br />
}<br />
);<br />
|
|
|
|
|
I have a DataGridView that has a DataTable set as the data source. When I add a row to the DataTable, it does get added to the grid but it is followed by a null row that sits between the row I just added and the next new row. How do I prevent this bogus row from appearing on the data grid?
|
|
|
|
|
Often when there is a null row there is an error in the code that is adding rows to the DataTable. I would check that logic.
If you would rather apply a hack than a fix to the error you can capture the Data Binding events for the DataGridView and manually remove the null records.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|