Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 2005 > C# 2005
|
C# 2005 For discussion of Visual C# 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old September 26th, 2006, 02:25 PM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Default how to call file using full path

Hi,

I've very simple question and I wanna makesure the correct way to do it. Anybody knows how to call the file using full path to the file. In this case, the file is located in many layers of folder. For example, I wanna call file 'pass'. File 'pass' in folder A, Folder A was in folder B. Folder B was in folder C and folder C was in desktop. Then, how to call file 'pass' with the full path. Thanks in advance.

 
Old September 26th, 2006, 11:47 PM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to guntank
Default

In stead of composing the path manually, it is more convenient if you use OpenFileDialag object.
The following is a simple way to obtain the full name path of a file:

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolde r.Desktop);
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                String fileNamePath = ofd.FileName;
                //Add your extra operation below
            }
 
Old September 27th, 2006, 11:09 AM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi guntank,

Thanks for your respond. But I think u misunderstood with my problem. Actually I got other different problem to my programming code. (Generic error occured in GDI+) and someone give me solution that : I should use the full path to the file that I call.
Therefor I need to know how actually the code to do that. I hope atleast I got some hint. Thankyou.



 
Old September 27th, 2006, 05:21 PM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to guntank
Default

Step 1:

String str = Environment.GetFolderPath(Environment.SpecialFolde r.Desktop);
str += @"\c\b\a\pass.jpg";


Step 2:

To call an image file, for example, write as follows

Bitmap bmp=new Bitmap(str);

Summary:
A full path must begin with a root directory followed by any available subdirectories and ended with a file full name (including its extension such as .jpg for example).
To avoid using escape sequence for backslashes, you can use verbatim, so
"c:\\first\\second\\file.xxx" can be written in verbatim as @"c:\first\second\file.xxx".

I hope it can be the hint that you want.

Andi Setiawan
 
Old September 27th, 2006, 11:25 PM
Authorized User
 
Join Date: Sep 2006
Posts: 11
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Andi,

Thanks for your respond. It's really helps and have solve my problem. However my original problem still not solved. Actually my original problem is:

I want to do image processing with real-time image and I’m using C#. I got to grab the image from webcam and it runs smoothly. However, I got some error when I attach with other code for image processing. I cannot run more than one time in one execution debugging.
It gives exception: “Could not grab picture. A generic error occurred in GDI+.”

I just attach one class library to do threshold process for color image that I grabbed.

This is the original class to grab the image:

---------------------------------------------------------------------
toolBarBtnGrab.Enabled = true;
int hr;
if( sampGrabber == null )
return;
hr = sampGrabber.SetCallback( null, 0 );

int w = videoInfoHeader.BmiHeader.Width;
int h = videoInfoHeader.BmiHeader.Height;
int stride = w * 3;

GCHandle handle = GCHandle.Alloc( savedArray, GCHandleType.Pinned );
int scan0 = (int) handle.AddrOfPinnedObject();
scan0 += (h - 1) * stride;
Bitmap b = new Bitmap( w, h, -stride, PixelFormat.Format24bppRgb, (IntPtr) scan0 );
handle.Free();
savedArray = null;
Image old = pictureBox.Image;
pictureBox.Image = b;
pictureBox.Image.Save("1stImage.Jpeg", ImageFormat.Jpeg);



---------------------------------------------------------------------
and below is the code that I added after the last line of above code to call class library for threshold the image that was grabbed by above code:

---------------------------------------------------------------------


Bitmap bp = new Bitmap("1stImage.Jpeg");
ClassLibrary1.Class1 filter = new ClassLibrary1.Class1();
System.Drawing.Bitmap binary = filter.Binary(bp);

picClass1.Image = binary;
picClass1.Image.Save("Binary.Jpeg", ImageFormat.Jpeg);
picClass1.Width = binary.Width;
picClass1.Height = binary.Height;
---------------------------------------------------------------------

And after several trial and error, I found that the maybe the error is caused by this code :

Bitmap bp = new Bitmap("1stImage.Jpeg");

And someone tell me that I have to use full path to call the image file.--> http://www.syncfusion.com/FAQ/aspnet/WEB_c27c.aspx

However, the problem still remain there. Do you have any idea about it? What have I do now? I'm really2 stuck here. Do you familiar with GDI+? Anybody can help me?? Thanks.









Similar Threads
Thread Thread Starter Forum Replies Last Post
Need path from Open dialog box call bab02 Access 2 October 26th, 2007 09:47 PM
Extracting the full path of a folder vamshikrishnaD ASP.NET 1.0 and 1.1 Professional 3 August 2nd, 2007 09:16 PM
Link doesn't display full file name sherbir J2EE 0 July 17th, 2004 12:30 AM
Retrive full path name from uploaded file itsp PHP How-To 3 June 10th, 2003 07:02 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.