I have tried below two methods and ensured that license is updated along with the correct binary. Using .net framework 4.5.2. Below using doc.save method is not working.
Option 1:
doc.Save(LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype,SaveFormat.FormatDocument, SaveType.OpenInWord, this.Response);
Option 2:
doc.Save(this.Response, "LetterTemplateEntity.CRSC_LETTER_TEMPLATE_DESC + doctype", ContentDisposition.Inline, null);
Acccording to the documentation, there are several overloads of the method Document.Save() that you can use :
https://apireference.aspose.com/words/net/aspose.words/document/methods/save/index
However make sure that you are not locking the file you read (after opening the file and executing your program at the same time).
You must use one stream (MemoryStream) for reading and another one for writing.
Also make sure Visual Studio (run as admin) have access to the location where you try to write the file at, in case you run the program from Visual Studio.
Related
i am reading a ini-file using the Kernel32-solution (GetPrivateProfileString). It was working fine under XP but now it is (not) running under Windows-7.
Now i have the problem that windows7 protects the file and i cannot write into it (with another program).
As soon as i open the ini-file with kernel32 it is blocked forever until i close the program.
Is there any parameter to simply reading the ini- file without write-protecting it?
Or any other solutions on reading an ini-file?
I am using C# 2010 express
Thanks for help
Edit:
Meanwhile i tried to copy the original ini-file to a second-file and then i am only reading the copied ini-file with the kernel32-functions.
But now it seems that the simple copy command
System.IO.File.Copy(PathOriginal, lokalPath, true);
is blocking the original file for the other program after it is copied.
So my problem is not with the ini-file now. It is file-protection in generall under windows 7.
Is there a trick to "free" the handle of the file i windows 7?
Try out Nini, which is a 100% C# version (no DLL/PInvoke required). There's a NuGet package as well.
Example INI file:
[Cars]
model = Toyota
year = 2012
The C# code:
Nini.Ini.IniDocument doc = new Nini.Ini.IniDocument ("configuration.ini");
Console.WriteLine ("Model: " + doc.Get("Cars", "model"));
Console.WriteLine ("Year: " + doc.GetInt("Cars", "year"));
Check out this IniReader library. It may help you with your problem:
http://www.mentalis.org/soft/class.qpx?id=6
I am building a wrapper for the Perforce .net API and I need to be able to download files from the Depot directly to my computer (not a check out!) as the file will be used in another project!
Currently I have a (quite special) solution where I run the "copy" command without submitting, copies that file to the correct location using the File.Copy function and then reverting the P4 copy. It works, but when the file is too big (~200 mb) I will get this error instead:
[Command time out[655371]: copy //FROM_PATH //TO_PATH]
I noticed that if you right click a file in the P4V you can choose the option "Export to...", I cannot find a command like that using the API or the command line... does anyone know a better way of exporting files than the one I currently use? (it needs to be able to run from a C# application)
Alternatively, if anyone knows how to bypass the Command time out, that would also be great!
Thanks!
Edit:
I found the solution to the Command time out:
You can change the delay until a time out occurs by creating a new instance of the TimeSpan class with the desired delay and then assigning it to the CommandTimeout variable of your connection instance (when you have a connection established):
example:
m_connection.CommandTimeout = TimeSpan.FromMilliseconds(milliseconds);
I am still interested to see if anyone knows a way of exporting files without having to do my strange version!
Are you looking for the 'p4 print -o' command?
so what I'm trying to do is open a file (well, actually two folders, but I figure I'll start with a single file for now) using a third party comparison tool called UltraCompare. I'm working in a C# website project in Visual Studio 2010 (Express edition). I've seen how to open a file using a different program, here: Open a file with Notepad in C#.
Problem is, this only lets you open it using the default program for that file type. But I want to open it in a specified program. For example, a text file should open in UltraCompare, not notepad. Here's the code which does this:
string textBoxContents1 = TextBox1.Text;
Process.Start(textBoxContents1);
The textbox on the webform accepts a string, in which the user types the file's full path (not the most user-friendly design I know, but I'm not sure how to allow them to browse for a folder using a GUI interface in asp.NET). The file is then passed into the Process.Start() method, which opens it using the default program for that file type.
Is there any way to modify this to make it open using UltraCompare??
You can specify the program you want to open the file in:
Process.Start("yourprogram.exe", textBoxContents1);
Update
To open two files in Ultracompare, you'd probably do something like that:
Process.Start("yourprogram.exe", "file1.txt file2.txt");
Keep in mind that the second parameter of Process.Start method are the arguments passed to the program.
I said this is probably going to work because I assumed to be very likely that Ultracompare expects 2 arguments, but this might not be the case.
Quick question: Are you trying to do this for the client machine? Hope not
And I guess it looks into the PATH variable for finding your exe
I have a MS Access Database that has a button on it that is supposed to run a tool that I wrote. The tool works. The Access DB works. The VBA to run the tool works.
However, there is an issue when running the tool from VBA. It always crashes when trying to load XML configuration data. I tested this by checking my Error Reporting tool (Control Panel -> Administrative Tools -> Event Viewer). I also wrote a second version of my tool which has all of the XML data hard-coded into it.
I am wondering if there is a known reason for this to occur, and if there is a workable solution for getting around this error. Hard-coding all of my configuration data is not really an ideal solution, as the configuration data needs to be modifiable without having to recompile the entire project and push out an update.
Information:
MS Access 2010 with Visual Basic for Applications (using Shell for
application calling)
C# application with XML configuration data using references (IO, Linq, Xml.Linq, Data.OleDb, Globalization)
Thanks for any assistance you may be able to offer.
Per request, here is the code I use to run the application:
Dim hProcess As Long
Dim myPath As String
dim myFile As String
myPath = Environ("ProgramFiles(x86)" & "\mytool\"
myFile = "mytool.exe"
hProcess = Shell( myPath & myFile, vbNormalFocus )
The application is a WinForms application that allows the user to map column names in a csv to fields in access. The only actual issue is the part where it attempts to load the XML configuration data:
XDocument xDoc = XDocument.Load(Environment.CurrentDirectory + "\\config.xml");
Again, if I hard-code the configuration data into the application itself, there is no issue at all when running the application. However, if I attempt to load the XML configuration data, it gives an Error Event in the Event Viewer stating that there was an unhandled exception when loading the XML file. If I run the application outside of the VBA Shell call, it runs fine and can load the XML file. It only ever crashes when trying to load the XML from VBA Shell.
In my experience, executing .NET code from MS Access seems to "mess up" some of .NET's "get the current directory" methods, which all work fine if you run the exact same .NET application directly without Access.
If you want to see what I'm talking about, create a new console application in Visual Studio and paste the following code:
using System;
using System.IO;
namespace CurrentDirTest
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Environment.CurrentDirectory);
Console.WriteLine(Directory.GetCurrentDirectory());
Console.WriteLine(System.Threading.Thread.GetDomain().BaseDirectory);
Console.WriteLine(AppDomain.CurrentDomain.BaseDirectory);
Console.ReadLine();
}
}
}
When I run that directly from Visual Studio, it outputs this (as expected):
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug\
C:\Dev\Code\CurrentDirTest\CurrentDirTest\bin\Debug\
Now put the compiled .exe in your Program Files (x86)\mytool\ folder and try to call it from Access, with the VBA code from your question.
When I do that on my machine, I get this:
C:\Users\MyUserName\Documents
C:\Users\MyUserName\Documents
C:\Program Files (x86)\mytool\
C:\Program Files (x86)\mytool\
Weird, isn't it?
Environment.CurrentDirectory and Directory.GetCurrentDirectory() both return my "Documents" folder as soon as the application is executed from MS Access.
I've got no idea why this happens, but it does.
Solution:
If you get the same results on your machine as I do on mine, the solution for your problem is simple: just use System.Threading.Thread.GetDomain().BaseDirectory or AppDomain.CurrentDomain.BaseDirectory to get the current directory.
Just in case someone has a similar problem when using COM-Interop:
The problem is even worse when you execute a .NET assembly via COM-Interop from MS Access.
If I recall it correctly, both System.Threading.Thread.GetDomain().BaseDirectory and AppDomain.CurrentDomain.BaseDirectory didn't work for me either because both returned the directory of the msaccess.exe.
I had to use this.GetType().Assembly.Location to get the actual location of the .NET assembly.
I need to create a resource file for a .net project (by hand) and compile it using the ResGen.exe tool provided by the .NET framework. I can't find any documentation for this. I need to write the resource file by hand because I'm in a situation where I don't want to download/buy extra tools (like VS) to generate this resource file, and also I feel more productive through the command-line (helps me understand how things really work).
So I need to write a resource file by hand to store an ICON in the executable and use it from within my program. I would also like to use this icon to represent my executable in Windows Explorer.
Any references would be great!
Visual C# Express Edition will do what you want for free. If nothing else you can download that, create the resource file and then use that as a subject for your admirable curiosity about 'how it really works'. This may also save you some time in manual experimentation to get it right the first time around.
These 2 links in conjunction provide information on using that tool to create and embed an icon file, it seems specific to C#. Of course i'm guessing at your full intention, let me know if this points you in the proper direction.
http://www.xtremedotnettalk.com/showthread.php?t=75449
specifically there is a post which states;
I think you should first create a *.resources-File from the Icon with the tool named "Resgen.exe"...
resgen App.ico App.ico.resources
the next step would be compiling...
csc /t:winexe /out:Keygen.exe /res:App.ico.resources /r:Crypto.dll /win32icon:App.ico Keygen.cs AssemblyInfo.cs
I'm sure you were here already.
http://msdn.microsoft.com/en-us/library/ccec7sz1(VS.80).aspx
You should check this link:
http://msdn.microsoft.com/en-us/library/ekyft91f.aspx
It explains what formatter is used and gives some code samples to generate one from code. You could then write a small wrapper app that you can call from the command line. No downloads needed!