|
Hi,
I'm not very good at RegEx , I want to use RegEx class to match values with desired string. My main string looks like this:
<%#String.Concat ..blah blah.. %>
in above string I want to get all the matches which between double quotes ( " ... " ) in blah blah part.
What is my expression should look like?
Thanks for your help
Mazy
"This chancy chancy chancy world."
|
|
|
|
|
you should post in no more than one location (a single forum, or Q&A) so everything about this topic stays together.
|
|
|
|
|
What do you have so far?
Also see my RegEx tester[^] and Expresso.
Edit: I coulda sworn I replied in the RegEx forum!
modified on Sunday, September 5, 2010 11:41 PM
|
|
|
|
|
Hi all,
I am doing a very simple operation via c#.
1 I just copy an existing JPEG file in temp directory.
2 Then I open the copied Jpeg file from temp directory.
3 I try to delete the original Jpeg file and application crashes.
Please see below c# function for this:
using System.IO;
public void DeleteAfterCopyingOriginalImageFile(string strOriginalJpeg)
{
string strTempFolder = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "JpegTemp");
if (!Directory.Exists(strTempFolder))
{
DirectoryInfo directory = Directory.CreateDirectory(strTempFolder);
directory.Attributes = directory.Attributes | FileAttributes.Hidden;
}
string strTempJpeg = System.IO.Path.Combine(strTempFolder, "TempImage.jpg");
if (!File.Exists(strTempJpeg))
{
File.Copy(strOriginalJpeg, strTempJpeg);
}
Process.Start(strTempJpeg);
File.Delete(strOriginalJpeg);
}
I need to follow exactly these steps (cannot delete original file before opening TempImage.jpg). Can anybody help in knowing why copy and opening of temp file lock the original file. How can I prevent original jpeg file from being locked. I am new in .Net. Please help me.
More Info about the user case:
The user case is that user cannot perform any operation on original file. So a temporary copy of original file is created in temp folder. User can then open/edit temp file. And if he thinks that he can replace original file with that of edited (copied in temp directory) one or he does not need original file any more, he can delete original file (and if required, can make temp file as the original one). So I strictly need to follow the same steps.
Regards
Aseem
Thanks in Advance
modified on Sunday, September 5, 2010 10:18 AM
|
|
|
|
|
Why not move[^] the file rather than copy it?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Hi Mark. Thanks for the reply. Actually I cannot move the file. The user case is that user cannot perform any operation on original file. So a temporary copy of original file is created in temp folder. User can then edit temp file. And if he thinks that he can replace original file with that of edited (copied in temp directory), he can delete original file and make temp file as the original one. So I strictly need to follow the same steps.
Regards
Aseem
|
|
|
|
|
It seems you are making it much more difficult than it is. The user can edit the file all they want, when finished they save it, otherwise don't save it. No need for two file and all the copy/move activity. There are plenty of apps the come with undo features also, such as this A simple framework for adding undo/redo support[^]
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
Yes, you are right in that these steps can be minimized by as you said. But this is not possible in my case. Reasons for this:
1 This is DMS application.
2 User can edit (or simply open) the temporary copied file in some third party application like paint brush or something else. My application only helps in opening the temp file in third party application. Thereafter we don't keep the track with what the user does with the file. In case he simply view the file and find that he does not need it, he can delete the original file. So its the business case like this only which cannot be avoided.
|
|
|
|
|
I still see no need for a temp copy of the file. Once it is opened in the third party app the use can chose to save it or not. It's up to the third party app the provide functionality for undo/redo, overwriting, copying, etc., not your app.
Aseem Sharma wrote: So its the business case like this only which cannot be avoided.
Blindly attempting the implement everything the user wants in the manner in which they want is a sure failure. It's up to the architect or lead developer to present alternatives that can accomplish the same goal in a more reasonable fashion with better use/reuse and extensibility. From what I see you need to reevaluate your implementation and possibly requirements.
Good luck.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
One more requirement of my application is that I do not want to let the user know where the original file is present. User can just click a thumbnail from my application to open it. My application then makes a copy of original file in temp folder and open that temp copy of file.
And whatever the user case is, I think I am doing something wrong in my code that deleting original file generates exception and crashing my application. Just opening (and not even editing) the temp file should have no impact on the deletion of original file.
|
|
|
|
|
That depends entirely on how the app is using the file in the first place. If you're doing something like getting a thumbnail of an image file, your app is probably keeping the file open for the like of the thumbnail, in which case, you won't be able to delete it.
|
|
|
|
|
Yes, you are absolutely right. It was the Thumbnail who keep the original file locked. I myself started looking into some irrelevant way. Your reply made me check the Thumbnail part of code and I could fix my problem.
Thanks for this.
Best Regards
Aseem
|
|
|
|
|
A few suggestions:
1.
put all of it inside a try-catch and show the entire Exception.ToString().
2.
is the original file path a fully qualified path? is there any chance both paths get resolved to the same file?
|
|
|
|
|
1 Here is the Exception details
"System.IO.IOException: The process cannot access the file 'MyPhotograph.jpg' because it is being used by another process.\r\n at System.IO.Directory.DeleteHelper(String fullPath, String userPath, Boolean recursive)\r\n at System.IO.Directory.Delete(String fullPath, String userPath, Boolean recursive)\r\n at System.IO.Directory.Delete(String path, Boolean recursive)\r\n at NG.DataRep.CleanImage(String strFile) in E:\\Aseem Sharma\\KB\\My Software Development\\NG\\DataRep.cs:line 153"
2 Yes, I have confirmed, original file path is a fully qualified path and both temp file and original file are different file path.
|
|
|
|
|
Aseem Sharma wrote: The process cannot access the file 'MyPhotograph.jpg' because it is being used by another process.
That process is either your own app because you created and Image or Bitmap using a .FromFile method, which keeps the file open for the lifetime of the Image or Bitmap object. You have to use a different method for getting the image without locking the file open. This would probably be supplying your own FileStream object, opeing the file, then passing that to the contructor of the Image or Bitmap object, then closing the file. That process does not lock the file allowing you to do whatever you want.
|
|
|
|
|
The original file must have a handle to it then - either you are getting this somewhere in your code, or another process is. To find out which, use ProcessExplorer and search for any handles to this file.
|
|
|
|
|
Thanks for your reply. I have fixed the problem. You were right in that my application was itself holding the file handle. Thanks for helping me.
Best Regards
Aseem
|
|
|
|
|
Do you mean Process Explorer is task manager or is it separate window in visual studio editor. If it belongs to visula studio, could you let me know where can I find it. Thanks in advance.
|
|
|
|
|
NarVish wrote: Do you mean Process Explorer is task manager or is it separate window in visual studio editor.
Neither. It's one of the most useful utilities you can download. You can get the latest info here[^].
|
|
|
|
|
|
Hello,
I need to make COM IntetrOp at runtime using reflections. My native COM Object's exposed methods have some parameters as pointers (DWORD*) and some double pointers (DWORD**) and some are user defined types(e.g SomeUDTType objSmeUDTType) and vice versa its pointer(i.e. SomeUDTType *pSomeUDTType).
Now for dynamic method invocation, we have single option for passing parameters as array of object i.e object[] and filling this array statically.
But I need to pass pointers and references and pointers to pointers. For now how can I be able to populate object array as mixed data of simple data types, pointers or references and pointers to pointers.
Working Example:
Native COM exposed method :
STDMETHODIMP MyCallableMethod(DWORD *value_1,BSTR *bstrName,WESContext a_wesContext)
Translated by tlbimp.exe (COMInterop)
UDTINIDLLib.RuntimeCallingClass.MyCallableMethod(ref uint, ref string, UDTINIDLLib.WESContext)
Now calling these methods at runtime using reflection at runtime,
See here :
Assembly asembly = Assembly.LoadFrom("E:\\UDTInIDL\\Debug\\UDTINIDLLib.dll");
Type[] types = asembly.GetTypes();
Type type = null;
//foreach (Type oType in types)
{
try
{
type = asembly.GetType("UDTINIDLLib.RuntimeCallingClass");
}
catch (TypeLoadException e)
{
Console.WriteLine(e.Message);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
object parameters = new object[3];
Type CustomType = asembly.GetType("UDTINIDLLib.WESContext");
object oCustomType = Activator.CreateInstance(CustomType);
FieldInfo fieldInfo = CustomType.GetField("MachineName", BindingFlags.Public | BindingFlags.Instance);
string MachineName = "ss01-cpu-102";
string MachineIp = "127.0.0.1";
string Certificate = "UK/78T";
fieldInfo.SetValue(oCustomType, MachineName);
fieldInfo.SetValue(oCustomType, MachineIp);
fieldInfo.SetValue(oCustomType, Certificate);
object obj = Activator.CreateInstance(type);
MethodInfo mInfo = type.GetMethod("MyCallableMethod");
int lengthOfParams = mInfo.GetParameters().Length;
ParameterInfo [] oParamInfos = mInfo.GetParameters();
object[] a_params = new object[lengthOfParams];
int ValueType = 0;
for(int iCount = 0; iCount<lengthOfParams; iCount++)
{
a_params[iCount] = ???; //Now here this array should be populated with corresponding pointers and other objects (i.e WESContext's obj)
}
mInfo.Invoke(obj, a_params);
Hope code will clarifies ...If any any confusion do let me know I'll edit my question accordingly.
I am stuck here , I'll be obliged if you help me out.(I am confused about "dynamic" keyword might hope it solves the problem)
Regards
Usman
|
|
|
|
|
i found many articles about creating custom files in .net, they explained well.
but in my scenario differ. my application is capturing four types of data simultaneously.
they are x,y coordinates , video , voice and ,pictures and save in relevant formats. now i want to create single file putting these four files in to one ,so i would like to know how can i do this and after creating single file how can i break this in to four formats again.
appreciate your ideas ...
thanx in advance.
|
|
|
|
|
You could combine the files into an archive with a custom extension. That is what a lot of application do, for instance a cab file is an archive many files with the cab extention.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I agree with Mark. Use an archive with a custom extention. This is also what MS have done for the latest office formats (docx, xlsx etc), they are just a collection of xml files in one zip with a custom extension.
DaveIf this helped, please vote & accept answer!
Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
|
|
|
|
|
As mark says you could just use an existing container format, e.g. zip and create an archive with your individual files. You could also password protect the file and also change the extension if you need to.
Another option might be to make a custom object with all the data in it, and then serialise and de-serialize the data from disk. your application would then work with the data object as required.
|
|
|
|