I have these lines of code in a loop:
rfmSheet.Cells[i, 18].Formula = String.Format("=VLOOKUP(O{0},[POvsPT.xlsx]Sheet1!$H:$K,4,0)", i);
rfmSheet.Cells[i, 19].Formula = String.Format("=VLOOKUP(P{0},'[PT Vendor.xlsx]Sheet1'!$A:$C,3,0)", i);
Both files are in the same directory and I open them both prior to the execution of the loop.
The first vlookup formula does it's job perfectly but the second one gives a pop-up requesting that I should open the file, although it's already opened. What am I doing wrong here?
EDIT
So after doing more testing it seems that the first file got opened because somehow I saved a copy of it in Documents and it fetched it from there. After deleting it the open dialog appeared.
Is there a way to make the formula see that the file is already opened? I'm really stuck with this...
Related
**Hello, my Visual C# is running but when I enter a person's name in Form1.cs[Design] it won't open the file. My code is below and I'll also attach how I saved my txt and what errors are showing. I been trying to figure this out for hours. My goal is to learn how to save txt in my directory folder and how to call it in the .cs code.
`` ```
Errors
enter image description here
tldr;
Your filename is 'BoysNames.txt.txt'.
From the image it is clear that the exception occured, because there is no file called 'BoysNames.txt' in the current directory. I see what the problem is. You have hidden the extension of files and still the text file is displayed with its extension. (Note that since the 'exe' file doesn't show its extension but 'txt' is showing. It means it has double extensions). So, you need to do this:
boysFile = File.OpenText('D:\\visual c#\\pp22\\bin\\Debug\\BoysNames.txt.txt');
To avoid this type of problems in the future, try these steps.
Go to Control Panel.
Click on File Explorer Options -> View
Uncheck this Option 'Hide extensiobns for known file types'
Well it looks like it will not open the file because it is not where you are saying it is. Look in the error, it tells you where it is looking for the file, is it really there?
I just finished this tutorial - Create a Picture Viewer - on the MSDN site, and it all works well according to the tutorial specifications (although I did remove the unnecessary buttons).
At the moment, I can open an image file from within the program, which is fine.
However, I'd like to be able to open an image file from Windows Explorer, and have it open in my Image Viewer. (Using the Open With.. context menu).
I did try and open it via the Open With.. menu, but when the program loaded, the image didn't show up. The program just started up as it normally would.
What code do I need to put in, that allows me to open the program via an image file (if that makes sense)
You can use:
Environment.CommandLine
Which will contain stuff in the format of "..." "...", first being the path of your application, and in your case - second would be the path of the opened-with file.
Then, you can split that to get the second "..." and load the file as you normally do in you application.
You can also check to see whether the arguments of the application contain the path of the opened-with file. I'm not sure about that, but it should be very easy to check: Have an mbox which prints the parameters, then try opening a file with your program and see what shows up. Using the args[0] or args[1] or whatever will probably be easier than splitting Environment.CommandLine...
I have an application that:
Copies a file
Pastes the copy with a new name
Modifies it
Saves it
This has been working fine, but then today, I've been getting this error:
Normal was being edited by another Word session. If you save this
document with the original name, you will overwrite any changes made
in the other session. Do you want to save the document using the
original name anyway?
And this is the file location of "Normal.dotm". I've never seen this file and am not manually accessing this file in any of my code.
C:\Documents and Settings\MyUserName\Application
Data\Microsoft\Templates\Normal.dotm
I'm running old code that has worked fine in the past, and I reset my computer, so I don't think any of my processes are screwing this up. What could be causing this? It seems like something happened externally to cause this problem, but I could be wrong. I'm genuinely stumped.
You might get this save message when you edit the styles or margin settings of the document.
Refer this
http://office.microsoft.com/en-us/word-help/change-the-normal-template-normal-dotm-HA010030756.aspx
I suppress this message in my application because we set some settings for Word when the document opens up
foreach (Word.Template template in Globals.ThisAddIn.Application.Templates)
{
switch (template.Name.ToLower())
{
case "normal.dotm":
template.Saved = true;
break;
}
}
I have noticed that if you have outlook opened it locks the normal.dotm file so check if your outlook is editing your normal.dotm file
This is what I'm trying to do :
Download a file (txt, doc, xls, whatever) from a server
Open the file with the appropriate application using System.Diagnostics.Process.Start(path to file)
Monitor for file changes using a FileSystemWatcher.
Each time the file is changed, upload the file back to the server
Continue monitoring until the user has finished editing the file
Delete the local copy of the file
Exit the application
I'm stuck at step 5. How can I know whether a user has finished working on a file ?
I cannot rely on the file being locked (notepad doesn't lock txt files for example).
I cannot rely on a process having exited or not (an example is Notepad++ for txt files : the file could be open in a tab. When you close the tab, you've finished editing the file, but the process is still running)
Any idea/points on how to do that in C# ?
You've excluded the two ways you could go about detecting the file being in use: file locking, and the process you start exiting.
The only alternative I an think of is to display a dialog to ask the user when they've finished editing.
Edit: For what it's worth - FileZilla has this type of behaviour. You can choose to edit a file on the remote server, it downloads the file, launches the default editor, and (in the background) shows a "If you've finished editing - Click OK" button.
This gives me the opportunity to cancel an edit, if I've mucked up the file and saved it.
This is really hard to do - we've tried various things but never found anything that was foolproof. If you know the program you have launched then, in theory, you can find the file handles it uses and see when it stops using the one you're interested in.....but if you rely on Windows to resolve the default application to launch even this becomes tricky.
We copy editable files into a temp folder named with the date and rely on users uploading them back when they have finished their edit session. We then clean up previous days folders on application startup.
You could check the date of last change of the file. This date gets set when you save changes to the file. Mind though that this field is not very reliable since one can set it to any value (with appropriate tools).
I have a program that start another program. In the second program, I try to delete a File.
If I run directly the second program, no problem, the file get deleted. But if I start the second program from the first program, I get a System.UnauthorizedAccessException.
My guess is that the second program doesn't get all the access of the first program.
I tried many suggestions I found but none of them worked.
Adding Process.StartInfo.Verb = "runas" didnt work.
Adding a manifest file didnt work either (or I did it wrong, not sure)
I set the .exe of the second file to "Run as Administrator" and it didn't work.
Now, how do I fix this?
The first program left the file open, so the second program cannot delete it.
You need to close the file in the first program.
You might be missing a Dispose() call on the FileStream (for example) used to access the file in the first program. That could leave the underlying file in use in that program, although you think the object instances associated with it are gone because they are out of scope.
Post some code if you want better feedback.