Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Saving blob field to the local system
 

Saving blob field to the local system

Hi,
I am trying to retrieve a blob field (License is stored in this field) from the database and later I want to store it into a local drive.
Following are the steps I am trying:

string filePath = @"C:\License.txt";
System.IO.FileInfo fname = new System.IO.FileInfo(filePath);
FileIOPermission permis = new FileIOPermission(FileIOPermissionAccess.AllAccess, fname.DirectoryName);

// Creating new OracleCommand Connection object
OracleCommand oc = new OracleCommand();

// Creating object of DataSet
DataSet ds = new DataSet();

// Adding Parameter to the Stored Procedure
oc.Parameters.AddWithValue(Constants.APP_INFO_ID, intAppInfoID);

// Retreiving Application Information in the Data Set
ds = nsTala.clsTala.BaseDB.GetDataSet(oc, "USP_USER_GET_LICENSE");

//using filestream object write the column as bytes and store it
//FileStream FS = new FileStream("Licence.txt", FileMode.Create, FileAccess.Write);
FileStream FS = new FileStream(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None);

byte[] blob = (byte[])(ds.Tables[0].Rows[0][0]);
FS.Write(blob, 0, blob.Length);
FS.Close();
FS = null;

Using this, I am able to store the blob field.
The problem with my code is that when I am deploying my code to a server, and trying to run the code, it is storing the converted file on the server (C: of the server where I have deployed the code) but not on the local machine from where I am running the server code.

Can you help me understanding how to take the path which is specific to the client not to the server?

hima
Himanshu Shukla 1  Friday, March 20, 2009 11:54 AM

Hi Hima,

Well, since you're going to save the file on the client machine, the machine name isn't necessary. You can specify the path to d:\some folder and save the file to this folder.

You can also let the user choose where to save the file on the client machine.

As for access right, applications coming from local intranet don't have the FileIO privilege to write on the local disk. You need to use the .NEt Framework 2.0 Configuration to grant the FileIO permission to the applications that come from the specified UNC.

Hope this helps.

Linda Liu  Wednesday, March 25, 2009 7:35 AM

Hi Hima,

Based on my understanding, you have an application on machine A. Now you browse to this application using UNC from machine B and run this application directly. You want the application to save files to machine A. If I'm off base, please feel free to let me know.

The Application.StartupPath property returns the path where the application is run. This path also contains the machine name.

Hope this helps.

Linda Liu  Tuesday, March 24, 2009 9:50 AM
Hi Linda,

According to your example, I want to save file on machine B (the machine which is trying to run Machine A's application). Let me elaborate more on that:

I have an application deployed on Server (Machine A).
The client (Machine B) have the URL of server, which in turn is trying to call the Server's method.
I want to store the processed data to a text file (may be temp.txt).
I want this temp.txt on Client's machine (Machine B).
Currently this is been stored in Machine A (Server).

The Application.StartUpPath will give me the path of Server (Machine A) which I don't want.

hima
Himanshu Shukla 1  Tuesday, March 24, 2009 11:20 AM

Hi Hima,

Thank you for your prompt response!

You can get thename of the machinewherean application iscurrently runningusing the Environment.MachineName property. In your case, this property will return the name of client machine(Machine B).

Hope this helps.
If you have any question, please feel free to let me know.

Linda Liu  Wednesday, March 25, 2009 3:36 AM
Hi Linda,

Can you please elaborate more on how can I use Environment.MachineName?
How can I associate Client's path using MachineName Property?

Even having a machine name with me, I need to have access right to write on that (Client) Machine.


hima
Himanshu Shukla 1  Wednesday, March 25, 2009 6:04 AM

Hi Hima,

Well, since you're going to save the file on the client machine, the machine name isn't necessary. You can specify the path to d:\some folder and save the file to this folder.

You can also let the user choose where to save the file on the client machine.

As for access right, applications coming from local intranet don't have the FileIO privilege to write on the local disk. You need to use the .NEt Framework 2.0 Configuration to grant the FileIO permission to the applications that come from the specified UNC.

Hope this helps.

Linda Liu  Wednesday, March 25, 2009 7:35 AM

You can use google to search for other answers

Custom Search

More Threads

• Problem with Windows Forms Inheritance in designer
• UITypeEditor question - placement
• Tab Control
• Is it possible to create short cut keys for each of my tab pages in my tab control?
• Why does the font keep reverting back to bold?
• Absolute -> relative path
• Properties window keeps giving me "Object reference not set to an instance of an object." error
• Undo/Redo does not preserve order of Container.Add calls on Redo
• visibility of controlls while editing.
• Tab index not working correctly