hi there,
i have a question in C# files. i have a client application which is created in visual studio C#. and from that i copy a file to a folder in the server computer folder. so when i am trying to display it ot the user i user System.Diagnostic.Prcess.Start(PathToTheFileInTheServer) (the file path is saved in the field in the database table.)
but there is a problem when one person has open file A and the second person tries to open file A he won't be able to open because the first person has opened it, what is the solution that i can use for this?

thanxxx
appriciate a lot

You can mark the server file as readonly. This will permit to be read by more than one client at a time.

Another way: Copy the server file in to an application temp folder in the current user profile and launch it from local. The temp folder can be cleaned at application shutdown and/or start.

Hope this helps

You can mark the server file as readonly. This will permit to be read by more than one client at a time.

Another way: Copy the server file in to an application temp folder in the current user profile and launch it from local. The temp folder can be cleaned at application shutdown and/or start.

Hope this helps

hi there how can i do the second way??/
please can you provide me with a tutorial?

The first way:

http://msdn.microsoft.com/en-us/library/y973b725.aspx

The open mode default option is Open or Create.
The access default option is Read-Write.
The file share default option is None.

When you launch a process with a file name, the OS searches for the default application to open the file, then applies the defaults to open the file with the application. This is by OS design.

If you need to opena file in 'shared' mode, you must specify it.

The second way:

If the user should not change the file contents, it can be copied into a temp folder and openen it from there (you will preserve the original from being modified).

Alternative: You will need 2 (or more) users modifying the same file, at the same time. Unless it is a database, IMO, there is no way.

Hope this helps

The first way:

http://msdn.microsoft.com/en-us/library/y973b725.aspx

The open mode default option is Open or Create.
The access default option is Read-Write.
The file share default option is None.

When you launch a process with a file name, the OS searches for the default application to open the file, then applies the defaults to open the file with the application. This is by OS design.

If you need to opena file in 'shared' mode, you must specify it.

The second way:

If the user should not change the file contents, it can be copied into a temp folder and openen it from there (you will preserve the original from being modified).

Alternative: You will need 2 (or more) users modifying the same file, at the same time. Unless it is a database, IMO, there is no way.

Hope this helps

hi please can you give me more information on the second way,
i am trying to implement it in C#

Assume you have a text file in the path \\MyServer\MyShare\Myfolder\MyFile.txt

var PathToTheFileInTheServer = "\\\\MyServer\\MyShare\\Myfolder\\MyFile.txt";
var sourceFileInfo = new System.IO.FileInfo(PathToTheFileInTheServer);

Then you should be confident than source file exists

if (!sourceFileInfo.Exists)
{
    // nothing can be done
    return;
}

You can use ...

var tempFolder = System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\" + System.Windows.Forms.Application.ProductName;

to obtain an application temp folder path within the local application data folder.
Then with

var dirInf = new System.IO.DirectoryInfo(tempFolder);

yu'll get the info about this temp directory. Then, if the directory does not exist, you must create it using

if (!dirInf.Exists){
    try
    {
        dirInf.Create();
    }
    catch(Exception exception)
    {
        // show a message box explaining the error or take any relevant action
        // in theory, you should be able to create it
    }
}

Then you need to delete the destination temp file if already exists

var destinationFilePath = tempFolder + "\\" + sourceFileInfo.FileName;
var destinationFileInfo = new System.IO.FileInfo(destinationFilePath);
if (destinationFileInfo.Exists){
    try
    {
        destinationFileInfo.Delete
    }
    catch (Exception exception)
    {
        // show a message box explaining the error or take any relevant action
        // in theory, you should be able to delete it
   }
}

Then you can copy the file to the temp folder

try
{
    sourceFileInfo.CopyTo(destinationFilePath);
}
catch (Exception exception)
{
        // show a message box explaining the error or take any relevant action
        // in theory, you should be able to copy it
}

Finally you can launch it

try
{
    System.Diagnostic.Prcess.Start(destinationFilePath);
}
catch (Exception exception)
{
        // show a message box explaining the error or take any relevant action
        // in theory, you should be able to launch it
}

At the application closing, maybe you want to clear the temp folder using

try
{
    dirInf.Delete();
}
// no catch really needed here

All this process will be able to copy the server file into the client local temp folder and launch it.

Hope this helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.