Showing posts with label anywhere. Show all posts
Showing posts with label anywhere. Show all posts

Wednesday, March 28, 2012

System.IO.Directory.GetFiles(path, searchPattern)

Hi

I don't know if this is the right place to put this post but I didn't found anywhere else.

The thing is that I'm getting files in a directory but I would like to pick only four types of files: .wmv, .avi, .mpeg and .mpg. I know that the search pattern works but I can only search for one type of file. Can extend the search to look for all 4 types?

Thx

It seems that there is no direct way to do this, really strange. Maybe you can get all files under the directory, and then use regular expression to get files of these types?

Hi

Thx for the reply. I already thought of that. I know it works cause I tried it. I just wanted another way to optimize unnecessary code. But thanks anyway lori_Jay

Tuesday, March 13, 2012

System.Runtime.InteropServices.dll not found.

HI, i am trying to reference the System.Runtime.InteropServices using C#, I can't find the dll anywhere. But VS.net didn't highlight System.Runtime.InteropServices statement. So I assume it is referenced.

When I do [MarshalAs (....)].

It says MarshalAs is not found, related namespace missing or not referenced, something like that.

1. How and where do I find System.Runtime.InteropServcies.dll?
2. what namespace I can find the MarshalAs?

thanksHi,
MarshalAsAttribute is part of System.Runtime.InteropServices namespace which resides in Mscorelib.dll assembly. No need for additional reference.
thanks for the reply,

[code]

using System;
using System.Runtime.InteropServices;

/// <summary>
/// Summary description for Class1.
/// </summary>
public class Class1
{
[DllImport("Kernel32.dll", LastAccessError=true)]
public static extern IntPtr FindFirstFile(string fileName, [ In, Out ] FindData findFileData);
}

[StructLayout(LayoutKind.Sequential)]
public class FindData
{
public int fileAttributes = 0;
public int creationTime_lowDateTime = 0;
public int creationTime_highDateTime = 0;
public int lastWriteTime_lowDateTime = 0;
public int lastWriteTime_highDateTime = 0;
public int lastAccessTime_lowDateTime = 0;
public int lastAccessTime_highDateTime = 0;
public int nFileSizeHigh = 0;
public int nFileSizeLow = 0;
public int dwReserved0 = 0;
public int dwReserved1 = 0;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 256)]
public string fileName = null;
[MarshalAs( UnmanagedType.ByValTStr, SizeConst = 14) ]
public string alternateFileName = null;

}

[/code]

The above code is just a simple class that i do and it is from msdn.

compile error stops at [MarshalAs, saying Class1.cs(30): The type or namespace name 'MarshalAs' could not be found (are you missing a using directive or an assembly reference?)

what is the problem?

thanks