|
Hi,
Is it possible to use extension methods in C# using .NET 2 ?
I'm using Visual Studio 2013.
Thanks
|
|
|
|
|
No.
Extension methods were introduced as part of V3.0 - if you want to use them, you must target .NET 3.0 or higher.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
v3.5, shirley? They were added with LINQ.
And, as Sascha said, if you're using the right version of the compiler, you can still use extension methods even if you're targeting v2.
There's even a library[^] which lets you use LINQ in v2, so long as you're using the right compiler.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I didn't know that!
And any day when I learn something new is...well...another day really.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
|
Yes. To make it work, you have to place this somewhere in your project:
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson
|
|
|
|
|
|
ok im trying to make a script placer witch will move loads of files at once and rename them depending what name is in the text box.
the only issue i have it im not sure on how to do this i know its a pain i know the basics of c# made a few programs just dont know how to connect a text box and button to move and rename multiple files all at once if anyone knows how to do this or could help me out a little with example code would be amazing i dont want anyone to create this for me just need a little bit of a understanding in this
thank you all for your time
thanks in advance elfenliedtopfan5
|
|
|
|
|
Many of the class methods in the documentation come complete with example code. For instance, https://msdn.microsoft.com/en-us/library/system.io.file.move(v=vs.110).aspx[^]
You can lead a developer to CodeProject, but you can't make them think.
The Theory of Gravity was invented for the sole purpose of distracting you from investigating the scientific fact that the Earth sucks.
|
|
|
|
|
can you have me? source code open, save as, and help menu..
example we work on notepad and then save with format (txt) and then open on our program (this program read the txt) then have result after that save as txt again..
in help menu, how to display new form (about) etc.. i dont understand.. help me to finished this project 
|
|
|
|
|
I'm afraid that you don't seem to understand the purpose of this site. If you have a need of software, take a look at our articles. If you're lucky, you'll find examples there that give you the help and information you need. If you cannot find a suitable article, then you need to provide us with a detailed explanation of what problems your code is facing. Show us the relevant code sections and explain clearly what errors you are seeing.
What we don't do is write your code for you. That's your responsibility I'm afraid.
|
|
|
|
|
Member 11773338 wrote: help me to finished this project
It doesn't really sound like you have started - much less need help to finish!
This is all pretty basic stuff: it's the kind of problem you give to students as homework after a week or two of a C# course, so pretty much you should know everything you need to solve it - probably in your course notes.
So give it a try: start small, and break it up into separate tasks. If you can't do one of them, break that up into smaller tasks and try again. Pretty quickly, you should find solving the little problems solves the big ones!
If you meet a specific problem, then please ask about that and we will do our best to help. But we aren't going to do it all for you!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
Hello guys. I used following tutorial as a guide for adding/modifying a satellite assembly.
Creating Satellite Assemblies for Desktop Apps.
I am able to create
1- new .resx file
2- create a .resource file from it
3- and create satellite assembly from the .resource file.
I use following two commands for creating assemblies
1: resgen string.en-US.resx
2: al /target:lib /embed:string.en-US.resources /culture:PATH TO DEBUG\en-US\TestApp.resources.dll
I create a new folder for culture I am interested in, in the Debug folder and place the newly created satellite assembly in it. When I run it, I get the exception
Could not find any resources for the specified culture or the neutral culture. Make sure "TestApp.string.resources" was correctly embedded or linked into assembly "TestApp" at compile time or that all the satellite assemblies required are loadable and fully signed.
One thing of interest here is: if I just recompile my project then changes made are picked up. But if I don't recompile my project then running the .EXE from debug folder gives this exception. WHAT COULD BE WRONG ??? (hopefully I described well) Thanks for any input.
This world is going to explode due to international politics, SOON.
|
|
|
|
|
The exception mesage says that resources are completely missing - not only for a specific culture. I'd suggest to get the project running without satellite assemblies first, and then add them.
By the way, en-US is typically the default culture, unless you explicitely set it to something else.
|
|
|
|
|
Yes. Everything is working fine if I run it without satellite assemblies. Then I add the assemblies and run it again, it works again.
Now I make a small change in the en-US.resx file. I generate xxxx.resources file from this .resx file and xxxx.resources.dll file (satellite assembly) from the resultant .resouces file. I simply replace the old satellite assembly with the new one. It gives the said exception. Unless I recompile the project, I won't work. What am I doing wrong here?
This world is going to explode due to international politics, SOON.
|
|
|
|
|
If I understand you correctly, you do a change in the main resource of the project but don't compile it. Then you manually propagate the change to the satellite assemblies. This means your satellite assemblies contain strings that are not in the main assembly. I assume that this is the problem leading to the exception. And if you compile the project again, so that the main assembly matches the satellite assemblies again, it will work. If this is what's happening, I think the behavior is by design.
The good thing about pessimism is, that you are always either right or pleasently surprised.
|
|
|
|
|
I change something in satellite assembly ( change in .resx --> generate .resources --> generate .dll using VS command line). No change in main assembly. Do I have to recompile the whole project again ORR just updating the satellite assembly should suffice ?
In my case, I have to recompile whole project whereas I think I should just update the satellite assembly and application should run. What am I doing wrong here ??
This world is going to explode due to international politics, SOON.
|
|
|
|
|
Good Day All
i have a Windows Service written in .NET 4.5 and it is hosted on a Server where there is Office with the Version Microsoft Word 2013 15.0.4420.1017
Microsoft Office Professional Plus 2013
and my Windows Service does a Mail Merge and create Documents on fly.
On my Development machine its working nicely i have Office
Microsoft Word 2013 15.0.4719.1000
Microsoft Office Professional Plus 2013
i have given all the Permissions to the LocaLService user, the Document is not Corrupt , i can open it with no Problem and all the contents are in good shape.
So on the Server i get this Error on my logs
Word was unable to read this document. It may be corrupt.
Try one or more of the following:
* Open and Repair the file.
* Open the file with the Text Recovery converter.
and LocalService is also Part of the Administrator Group for some desperacy reason to resolve this issue.
The File Path of the Document and the Extension is Correct
C:\LetterGenerator\Section78Notice.docx
thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Vimalsoft(Pty) Ltd wrote: Word was unable to read this document. It may be corrupt. So you need to check the file manually, to see if it is or is not.
|
|
|
|
|
I have opened the file its not Corrupt. i even installed the Service Pack1 for Office and now what is on the server version is now equal to the one on my machine.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.
The KB article lists several things that you need to check on the server. However, there is no guarantee that you will be able to get your code to work, or that it won't suddenly stop working for no obvious reason.
You might have better luck using the Open Office XML SDK to generate your documents:
Creating Documents by Using the Open XML Format SDK Version 2.0 CTP (Part 1 of 3)[^]
(Part 2 of 3)[^]
(Part 3 of 3)[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
We're going to start with you cannot run any Office application in a service and expect it to work. It's not supported, never has been, never will be. This means you can NOT use Office Interop in your service application.
You're going to need the OpenXML SDK to manipulate Office files. So now, what were you trying to do with this document once you had it open?
modified 23-Jun-15 10:51am.
|
|
|
|
|
hi Dave Long time.
Let us start here, i have a few applications that does the MailMerge Automatically but on a click of a button. The strange this is when test the service on my machine it works , the problem is when i deploy it its a problem. i have added some log files which actually pointed to the line of code
oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
Here its where i give word the Template it will use in my mail merge , i have the same code working nice in a Non-Windows Service and also on my debug on my laptop it works with no Problem.
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vimalsoft.com
vuyiswa[at]vimalsoft.com
|
|
|
|
|
Vimalsoft(Pty) Ltd wrote: Here its where i give word the Template it will use in my mail merge , i have the same code working nice in a Non-Windows Service and also on my debug on my laptop it works with no Problem.
You don't understand what you're doing and what's going on. It works in your dev and testing because you're not running the code AS A SERVICE.
When you deploy the code and run it as a service, it falls on its face.
I don't know how much clearer I can be. <insert any="" office="" app="" here=""> CAN NOT BE USED IN A WINDOWS SERVICE. IT WILL NOT WORK.
What everyone is telling you is that you cannot do this as a Windows Service application. Period.
|
|
|
|
|
You have a license for Word that allows you to do this? Install it on a server and have it automated by "n" clients via a service? Must have been expensive....
|
|
|
|