It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
How to create a folder automatically when a solution is installed in the computer i.e( Local Disk:D) using c# windows forms?
Solution#1:
On first run of the application (make an xml file to track the first execution) you may create folder.
Solution#2: (Good one)
You may check if that directory exists ,if not then create the directory
try
{
// If the directory doesn't exist, create it.
if (!Directory.Exists(palettesPath))
{
Directory.CreateDirectory(palettesPath);
}
}
catch (Exception)
{
// Fail silently
}
Source:
check this link
How to Add Items to a Deployment Project
http://msdn.microsoft.com/en-us/library/z11b431t.aspx
Specifically:
How to: Add and Remove Folders in the File System Editor
http://msdn.microsoft.com/en-us/library/x56s4w8x.aspx
See the MSDN for more info, but the gist is:
You set the path like either of the ways below. See string literals for more info on this:
string newPath = #"c:\yourpath";
or
string newPath = "c:\\yourpath\\morepath";
To create the directory, you use this:
System.IO.Directory.CreateDirectory(newPath);
Hope this helps!
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am a student and working on winform c#. I have a small app and I want to add a new feature of memo reminder. For example, when I type something in a text box, the app saves it and set a timer of 8 hours. If the app is running, then a message should popup with the message I have saved.
It's not clear to me if I should use a database for reminding the entries or something else provided by c#. As far as I know all thing are automated. Is there anything which will help me to build this functionality, like a timer??
Store somewhere in the txt file if using database is not possible.
Like this:
3.20.2013 11:20:00 | Remind me something.
Then your timer checks every minute or so.
UPDATE:
Example:
DateTime savedTime = Convert.ToDateTime("date from the text file");
if(DateTime.Now >= savedTime)
{
MessageBox.Show("reminder from the text file");
}
UPDATE2:
string pathToStoreTXT = Application.UserAppDataPath;
pathToStoreTXT has the path something like: "C:\Users\UserName\AppData". Your timer need's to check for that folder all the time. Name your txt file like "MyReminders.txt".
Simple flow would be:
When app is run, check if file is created or not. This file will store your data!
Check if there is any record in the file or not.
2a. Show expired messages and clear them too.
Add timer like Dilshod has suggested.
3a. Convert reminder datetime as timestamp and concatenate it with message to store in text file
Create at a timer object with tick event every 1 minute, something like this. (Obviously you will need to set frequency which is passed as parameter)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have a problem with copying from local disk to flash. The code worked before, but after I create anoteher foreach loop and I had to create new objects, the File.Copy functionality isn't working anymore.
In value File | System.IO.File there are values like: Error_Access_Denied | 5, Error_Invalid Parameter| 87, GetFileExInfoStandard | 0.
edit: locationUSB present file path on flash. (locationUSB == "D:\something.hex") and x._location == "C:\something_1.hex" .
foreach (object item in this.dataGridView2.Rows)
{
versionOnDisk = this.VersionInt(x._version);
versionOnFlash = this.VersionInt(((DataGridViewRow)item).Cells[2].Value.ToString());
if (versionOnFlash > versionOnDisk)
forbidCopying = true;
else
locationUSB = _logicalDrive + ((DataGridViewRow)item).Cells["Filename"].Value.ToString(); // <-- location value (because of the foreach)
if (!forbidCopying)
File.Copy(x._location, locationUSB, true); // <--
else if (AllowDelete.Checked)
File.Delete(locationUSB);
}
edit:
If I change the location into logical drive path, which value is "D:\" I get the DirectoryNotFoundException was unhandled: Could not find a part of the path 'D:\'.
Most probably after creating new files, you are not closing the FileStreams. Close the FileStreams of the newly created files using either myFile.Close(); or create new files inside using (var myFile = File.Create(myPath)) blocks.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I want to show one detail_report page of my web application which is hosted on server.
We have used asp.net to create that application.
I have following list to show on detail_page
Host Name
Host Date/Time
Database Status
Build Version
Build Timestamp
I'm really trying to get Database Status using Ping but unable to do that.
anyone can help me I need to use asp.net + C#
Why do you need to ping database in order to get status of database?
Just handling the sql connection exception in your application will be enough to show the related information on server status. In addition to the exception handling, when your DB is down, you may also use connection string information to display the DB name, and other information from resource files like web.config.
However, i hope you don't have plans to display username and password of the connection string to your users :)
You may try doing something like this. Hope this helps.
public void displayDBDetails()
{
SqlConnection sqlConn = new SqlConnection(string yourConnectionString);
sqlConn.Open();
string dbName = sqlConn.Database.ToString();
string dbStatus = sqlConn.State.ToString();
string dbServerVersion = sqlConn.ServerVersion.ToString();
etc.....
}
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am trying to close the program :HHTCntrl.exe as if the user clicked exit on that program. I have the following Borland C++ code. What is the C# equivalent?
FILE *sf;
AnsiString ClosePollControl = AnsiString("HHT")+cbHHTNo->Text+AnsiString(".cls");
sf = fopen(ClosePollControl.c_str(),"w");
fclose(sf);
You're opening the file for writing. Assuming that cbHHTNo is the string containing file name, in C# it will go like that:
var path = "HHT" + cbHHTNo + ".cls";
using (var file = File.OpenWrite(path))
{
// do sth with the open file stream here
}
Well, it is actually pretty simple.
There isn't a concept of an AnsiString in C# so you have to use a string.
string ClosePollControl = "HHT" + cbHHTNo->Text + ".cls";
// Open the stream and write to it.
using (FileStream fs = File.OpenWrite(ClosePollControl))
{
}
This assumes you have some user level control, cbHHTNo, that you are getting the Text (e.g. string).
If you are trying to shutdown the process then use System.Diagnostics.Process class. For example,
Process process = Process.GetProcessesByName("HHTCntrl.exe").FirstOrDefault();
if (process != null)
{
process.Kill(); // to immediatelly kill the process or use process.CloseMainWindow() to gracefully "kill" the process
}
If you want to close an active form use Close() method.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm working on something like recycle bin, that I need to move folder/files to already existing folder, I tried to use
Directory.Move
but it creates new directory and that's wrong for me, I have a specific directory to move to.
Can you help me?
It seems do don't actually want to move the folder, you want to move the contents of the folder. If you want to do that, you have to tell the computer to do that:
void MoveContentsOfDirectory(string source, string target)
{
foreach (var file in Directory.EnumerateFiles(source))
{
var dest = Path.Combine(target, Path.GetFileName(file));
File.Move(file, dest);
}
foreach (var dir in Directory.EnumerateDirectories(source))
{
var dest = Path.Combine(target, Path.GetFileName(dir));
Directory.Move(dir, dest);
}
// optional
Directory.Delete(source);
}