473,320 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

file deletable?, shortcuts, .mdb file backup

Hi All!!
Could you please help me with three problems:

1.
I would like to have a procedure that returned true if the file is
writtable=deletable.. I tried everything but so far the only way I can
really tell if the file can be delete is to actually try to delete it and
catch an exception.. Trying to open a file with StreamReader in write mode
didn't work as expected.

2:
I know how to create shortcut, using COM API, but I can't seem to find
parameter for setting shortcuts name when put for example on Start Meni.. if
I don't set this, then the name of link is just the name of file, which is a
little bit ugly.

my code is here.. note the line, marked with ###

public static void CreateShortcut(string name, string shortcut_dir, string
app_path, string description)
{
// Get the app path and filename
//string app = app_path;
try
{
// Create a Windows Script Host Shell class
IWshShell_Class shell = new IWshShell_ClassClass();

//get application executable from entire path
string app_file = Path.GetFileName(app_path);

// Define the shortcut file
IWshShortcut_Class shortcut = shell.CreateShortcut(shortcut_dir + "\\" +
app_file + ".lnk") as
IWshShortcut_Class;

// Set all its properties
//### I thought the following line was what I was looking for.. but when
I tried to set this,
//compiler says it is only readonly field.. so.. my question is: is this
the field and this is the bug, or should I do something else to set the real
name of the shortcut which user sees?
//shortcut.FullName = name;
shortcut.WorkingDirectory = Path.GetDirectoryName(app_path);
shortcut.TargetPath = app_path;
shortcut.IconLocation = app_path + ",0";
if(description != null)
{
shortcut.Description = description;
}

// Save it
shortcut.Save();
}
catch(COMException ex)
{
Console.WriteLine(ex.Message);
}
}

3.
I would like to periodically make a backup copy of all .mdb files while the
application is running in the background (it is database server .. c#
remoting, ADO.NET).
The thing is that not all the recent changes are in those .mdb files, when I
copy them.. if I reset the server, then the files are up-to-date.
I see the solution in two possible ways:
somehow get all the data from ADO.NET objects and create new mdb files.
or..somehow forcing ADO, to write all the pending actions before physically
copying .mdb files.
I am currently traveling, so my access to internet, book and other
information is restricted.. I've been fighting with those problems for some
time, but then I came to blind alley. Your help would be greatly
appreciated.
Thank you so much!!!

David Krmpotic

Nov 16 '05 #1
2 2272
For your first question, you can check that if a file is ReadOnly or
not.

System.IO.FileInfo fi = new FileInfo("yourFilePathgoesHere");
if((fi.Attribute & System.FileAttributes.ReadOnly) ==
System.FileAttributes.ReadOnly) //If File is readonly
//Don't delete.

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #2
Thank you for response.. but I am afraid that this doesn't work for me.. I
think I didn't express myself clearly. I needed a procedure that would tell
me if the file is in use and thus not writable/deletable.

I tried your recommendation, but file's ReadOnly flag is not set when file
is in use.

I just found other easy solution:

public static bool IsFileInUse(string file)
{
try
{
FileStream fs = File.OpenWrite(file);
fs.Close();
return false;
}
catch
{
return true;
}
}

I was close before, but I used OpenRead instead of OpenWrite. The problem
was that you can open the file for reading although it's already open for
reading somewhere else (and thus not deletable). But you can only open the
file for writing it absolutely nothing is currently accessing it.
Thank you !!

PS: do you have any ideas about my second two questions.
"Maqsood Ahmed" <ma***********@gawab.com> wrote in message
news:eZ**************@TK2MSFTNGP15.phx.gbl...
For your first question, you can check that if a file is ReadOnly or
not.

System.IO.FileInfo fi = new FileInfo("yourFilePathgoesHere");
if((fi.Attribute & System.FileAttributes.ReadOnly) ==
System.FileAttributes.ReadOnly) //If File is readonly
//Don't delete.

Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Bing Du | last post by:
Greetings, Our former SQL Server 2000 DBA backed up everything in a single disk file. By everything I mean, full backup, differential backup and transaction logs. See below for details of how...
4
by: news | last post by:
Our production database in an exported textfil runs about 60 MB. Compressed that's about 9 MB. I'm trying to import the export into another machine running FC3 and mySQL 11.18, and it appears as...
3
by: Stanislaw Findeisen | last post by:
Does anyone know how to create file shortcuts in Windows? The only way I know is like: --------------------------------------------------------------- import win32com.client ...
6
by: Charles Morrall | last post by:
I have no experience with DB2 as such, but I've been tasked with configuring backup of a server running DB2 v8 on Windows Server 2003. I do have some experience with backups in general though. The...
23
by: Francesco Zavatarelli | last post by:
I downloaded a free c-compiler and I'm trying to access a file in a windows directory c:\program files\... but I get an error when I run the code. Probably my declaration char* NAME is wrong....
0
by: GeorgeF | last post by:
How can I conditionally deploy shortcuts to my application? I have created a custom installer dialog box to give my users the option of creating desktop/start menu shortcuts, but the shortcuts do...
4
by: Robert Iver | last post by:
Hello everyone, I am trying to create an application that utilizes a SQL Mobile database. I have included that database in my main project, and it compiles and debugs just fine. I then...
1
by: googleboy | last post by:
I need to create about 2000 shortcuts to a batch file. The shortcuts need to have: Name: %parameter%.lnk Target: n:\Path\To\batchfile.bat %parameter% Start In: n:\Path\To\ Where the...
3
by: maheshkadam | last post by:
Hi friends I am new to perl so please guide me. I have one application which created backup log file every day.But it appends that file so you can see logs for different day in one file only. ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.