Last post Mar 16, 2017 07:34 AM by Zhi Lv - MSFT
Mar 15, 2017 06:56 PM|G3n0c1de|LINK
I've got an asp.net Web Application in Visual Studio 2010, and I need certain aspx.cs files to use the Microsoft.Office.Interop.Word namespace.
If I try to use the namespace at all, like this:
Visual Studio gives me an error: `The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)`
I know I added the reference correctly. I've confirmed this by adding a new .aspx WebForm to the project, and within the .aspx.cs file I can reference the office namespace and call on all the functions and objects just fine.
I've found that if I then set the new .aspx.cs file's build action as "content", instead of "compile", and then change the header of the .aspx file to read "CodeFile=WebForm.aspx.cs" instead of "CodeBehind=WebForm.aspx.cs", then it breaks. The file can no
longer **see** the Office namespace. If I switch it back to "CodeBehind=", and "compile" the reference works. I can confirm that this issue occurs in new solutions and new Web Application projects.
The .aspx.cs files that I need to use the Office namespace are all set to build as content. I've tried switching them to compile instead, but for some reason this doesn't fix the issue. No matter the build action, they can't access the Office namespace.
Mar 16, 2017 07:34 AM|Zhi Lv - MSFT|LINK
I have added the reference and it doesn’t come to this error when I use
Codebehind and set the build action to content.
Please try it.
And why do you want to use Codefile?
You can refer to below link for the difference of codefile and codebehind: