I am trying to program a app for chain letters.
This is my Template: https://learn.microsoft.com/en-us/previous-versions/office/troubleshoot/office-developer/automate-word-create-file-using-visual-c
This is my code: https://github.com/440z/2021-07-01_WindowsFormsAppFuerKettenBriefMitWord
The error occurs in file Form1.cs in line 171.
Word._Document oDoc;
// ...
object oBookMark = "MyBookmark";
oDoc.Bookmarks.Item(ref oBookMark).Range.Text = "Some Text Here"; // L171
error CS1061: 'Bookmarks' does not contain a definition for 'Item' and no accessible extension method 'Item' accepting a first argument of type 'Bookmarks' could be found (are you missing a using directive or an assembly reference?)
I set a using directive and made a assembly reference how described in the template.
Add a reference to Microsoft Word Object Library. To do this, follow these steps:
On the Project menu, click Add Reference.
On the COM tab, locate Microsoft Word Object Library, and then click Select.
and
using Word = Microsoft.Office.Interop.Word;
using System.Reflection;
I just don't get it!!!
It looks like Bookmarks has an indexer, so: try one of
oDoc.Bookmark[ref oBookMark].Range.Text = "Some Text Here";
or
oDoc.Bookmark[oBookMark].Range.Text = "Some Text Here";
However, I would expect this to now complain that you're trying to access an invalid key, meaning: there is no existing bookmark keyed by "MyBookmark"
Related
I'm currently trying out the code for "Create a Customer Payment Instrument" by using their sample code and I am getting an error on this line.
var configDictionary = new Configuration().GetConfiguration(); error is "The type or namespace 'Configuration' could not be found".
Quick fix shows me to add one of these two Using statements: using CyberSource.Client; or using CyberSource.Clients;.
But this gives me another error - 'Configuration' does not contain a definition for 'GetConfiguration' and no accessible extension method 'GetConfiguration' accepting a first argument of type 'Configuration' could not be found."
There isn't much documentation so I am unsure how to fix.
I have two projects in the same solution and I have linked a class DatabaseFunctions.cs to the second one.
The problem is that when I reference it in the GUI_Teacher.cs I get the error:
Error CS0246 The type or namespace name 'DatabaseFunctions' could not be found (are you missing a using directive or an assembly reference?) Teachers application C:\Users\user1\source\repos\IASLSN\Teachers application\GUI_Teacher.cs
From the error, you are simply missing a reference.
Take the following steps to add a reference
Right click on the GUI_Teacher.cs project and click on Add Reference
From the left side of the Add Reference dialog, click on Solution
Select DatabaseFunctions.cs from the list and click OK to close the dialog.
In the source file DatabaseFunctions.cs you have something like
using System;
namespace SomeNamespaceName
{
public class DatabaseFunctions
{
}
}
To use the class in your GUI_Teacher.cs source file you need to add either using SomeNamespaceName; at the top or use the fully qualified type name SomeNamespaceName.DatabaseFunctions instead.
Keep in mind that the name of a sourcecode file like your DatabaseFunctions.cs for example has no connection to the name of a class or a namespace in that file. You can put a class like public class DatabaseFunctions { } in a file called foo.cs. And in the using directive at the top of your sourcefiles you provide a namespace and not a filename.
I have a c# application and I am adding a new button. When the button gets clicked I want to execute the following line:
WelcomeScreen channelBar = new WelcomeScreen(true, "http://www.trade-ideas.com/cms_static/ChannelBar/channelbar.html");
The problem is when I try to compile, I get the error message:
The type or namespace name 'WelcomeScreen' could not be found (are you missing a using directive or an assembly reference?)
WelcomeScreen is a class in a dll that I have referenced: TIProGUI. Any ideas what I need to do?
It could be that your "using" statements don't fully qualify the reference. For example System and System.Web.UI.WebControls will have separate uses.
Has anyone ran into problem where you just can't use the PageOrientation property in your C# WPF project? I have tried everything, put it still says:
"The name 'PageOrientation' does not exist in the current context".
I have all usings included, just can't figure it out.
Here's my printing method:
private void btnPrindi_Click(object sender, RoutedEventArgs e)
{
PrintDialog prtDlg = new PrintDialog();
if (prtDlg.ShowDialog() == true)
{
**prtDlg.PrintTicket.PageOrientation = PageOrientation.Landscape;**
Size pageSize = new Size(prtDlg.PrintableAreaWidth - 30, prtDlg.PrintableAreaHeight - 30);
gridKaart.Measure(pageSize);
gridKaart.Arrange(new Rect(15,15,pageSize.Width,pageSize.Height));
prtDlg.PrintVisual(gridKaart,"Patsiendikaart");
}
}
The error actually refers to the enumeration (PageOrientation.Landscape) on the right hand side of your assignment.
If the property did not exist you would receive (try compiling "".Y and you'll see what I mean):
'string' does not contain a definition for 'Y' and no extension method 'Y' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Compare this to Aoeui.Dhtns:
The name 'Aoeui' does not exist in the current context
You are likely missing a namespace reference required, like System.Printing:
// ...
using System.Printing;
// ...
The other possibility is you have not referenced ReachFramework.
If you have, your code compiles as-is:
I make a ListView control (with some column header) in my window form but when I run this code then it gives me error just like that
Line in my Form.cs file:
string packagename =
File.ReadAllText(Program.ProjectLocation + "\\" +
Program.ProjectName + ".aProj");
Error 'System.Windows.Forms.ColumnHeader'
does not contain a definition for
'ReadAllText' and no extension method
'ReadAllText' accepting a first
argument of type
'System.Windows.Forms.ColumnHeader'
could be found (are you missing a
using directive or an assembly
reference?)
So please help me remove this error.
I think that the problem could be this: did you call your listview or a column File?
If so, correct: System.IO.File.ReadAllText(...);
It seems that File refers to a variable of type ColumnHeader and not the File class in System.IO
What you need to do is right click the word file and choose "Go to Definition", most probably you will find something like ColumnHeader File = new ColumnHeader();
Either
Program.ProjectLocation OR
Program.ProjectName
is type of System.Windows.Forms.ColumnHeader, Add
replace
Program.ProjectLocation.ToString()
Program.ProjectName.ToString()
I don't know which one is System.Windows.Forms.ColumnHeader so make changes according to that
EDIT ANSWER:
Either
Program.ProjectLocation
OR
Program.ProjectName
is type of System.Windows.Forms.ColumnHeader,
Reeplace it with
Program.ProjectLocation.ToString()
Program.ProjectName.ToString()
Reason: ReadAllText("A valid file path as string"); But here you are trying to generate a file path by using column header so its throwing that error
I don't know which one is System.Windows.Forms.ColumnHeader so make changes according to that