Switch active view between two Revit Documents [closed] - c#

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a doc that is already opened in revit. A C# addin is activated and a form(modal?) is opened. A button event is then implemented to open a doc to transfer some mass elements from that file and document to the already opened document.
//the rvt file containing the mass elements opening code.
Document doc = app.OpenDocumentFile(UserRVTFilePath);
I then would like to switch the active document back to the first opened document. Is there a Revit API method that exists to achieve this?

Have you tried using the UIApplication.OpenAndActivateDocument(string revitPath) method?
public Result Execute(ExternalCommandData cmdData, ref string message, ElementSet elements)
{
UIDocument uiDoc = cmdData.Application.OpenAndActivateDocument(#"c:\project.rvt");
// do stuff with uiDoc
return Result.Succeeded;
}
Also you can get a reference to current Active UIDocument using: UIApplication.ActiveUIDocument

Related

WPF Saving UI settings to .txt file [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
I have a window with configurable controls where I can reposition them or hide them during runtime. Now my goal is to save current state of controls so whenever user closes an app and opens it again window shows last configuration of controls. I'm saving XAML to .txt file and then reading that file. Is it good/safe approach to use that kind of method? Are there better methods?
This question will most likely be closed for being opinion-based, but I would recommend saving your control states to the built-in WPF User Settings file that comes with your project, instead of creating your own. There's nothing wrong with creating your own, but why build your own parser when Visual Studio has already provided one for you. You will find this file under your project's Properties->Settings.settings file. This file gets automatically loaded when ever the user launches your WPF app. This file is stored in your %LocalAppData% folder, under the appropriate Company name and Product name, if you specified one.
Let's say the Settings.settings file contains the following states that you want to save:
Then in your code, find the appropriate time to load these settings into your app's variables:
// Load
string lastUser = Properties.Settings.Default.LastUser;
bool detailsEnabled = Properties.Settings.Default.ShowDetails;
int timeout = Properties.Settings.Default.FormTimeoutSeconds;
And when you want to save the control states, such as when the user closes your app, or changes a state value, do this:
// Save settings
Properties.Settings.Default.LastUser = lastUser;
Properties.Settings.Default.ShowDetails = detailsEnabled;
Properties.Settings.Default.FormTimeoutSeconds = timeout;
Properties.Settings.Default.Save();

Remove execute permission from uploaded folders and files [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 3 years ago.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
I am working on file and folder upload system and i want to add some security to it.
i have followed this Article , The security point number 6 on it says:
6. Keep tight control of permissions
Any uploaded file will be owned by the web server. But it only needs
read/write permission, not execute permissions. After the file is
downloaded, you could apply additional restrictions if this is
appropriate. Sometimes it can be helpful to remove the execute
permission from directories to prevent the server from enumerating
files.
How to apply that using C#
If I'm understanding you correctly, you want to upload a file to a remote server and then change the file to read only. Here is one option. Start by getting a File Object. After that you can set the access control then supply the access you want to provide.
It might be something like this:
using System.IO;
using System.Security.AccessControl;
private void SetFileAccess(string path)
{
var fileSecurity = new FileSecurity();
var readRule = new FileSystemAccessRule("identityOfUser", FileSystemRights.ReadData, AccessControlType.Allow);
var writeRule = new FileSystemAccessRule("identityOfUser", FileSystemRights.WriteData, AccessControlType.Allow);
var noExecRule = new FileSystemAccessRule("identityOfUser", FileSystemRights.ExecuteFile, AccessControlType.Deny);
fileSecurity.AddAccessRule(readRule);
fileSecurity.AddAccessRule(writeRule);
fileSecurity.AddAccessRule(noExecRule);
File.SetAccessControl(path, fileSecurity);
}
MSDN Link to File
MSDN Link to SetAccessControl Method
MSDN Link to File System Rights

How to know the page break in Excel using C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I´m using C# to create and format a Excel spreadsheet, so I need to format (merge cells, change the font, etc) until the final of the first page. How can I know the final line of the page in the Excel spreadsheet?
The following code will give you the last row number before every horizontal page break in an Excel worksheet:
foreach (Excel.HPageBreak pageBreak in worksheet.HPageBreaks)
{
int row = pageBreak.Location.Row - 1;
// ...
}

Is it possible develop an asp.Net application that creates events on Google Calender? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I am working on a personnel asp.Net project that has some calender based events. What I am thinking is if I can sync those events to a user's google calender.
Is it possible to create an application that create events on Google Calender? Is there a kind of API for this and if yes, would I have some limitations?
There is an API for it. check This link I think what you're looking for is the following:
EventEntry entry = new EventEntry();
// Set the title and content of the entry.
entry.Title.Text = "Tennis with Beth";
entry.Content.Content = "Meet for a quick lesson.";
// Set a location for the event.
Where eventLocation = new Where();
eventLocation.ValueString = "South Tennis Courts";
entry.Locations.Add(eventLocation);
When eventTime = new When(DateTime.Now, DateTime.Now.AddHours(2));
entry.Times.Add(eventTime);
Uri postUri = new Uri("https://www.google.com/calendar/feeds/default/private/full");
// Send the request and receive the response:
AtomEntry insertedEntry = service.Insert(postUri, entry);
If you have the calendar you are updating set as public, or you invite the other people, then they can subscribe to your calendar and any updates you put will show up on their calendars

Edit Metadata of PDF File with C# [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
i searching for methods or libarys to edit metadata of a pdf file like the programm becypdfmetaedit.
I want to write a program and i need this opton in this program.
Perhaps you have some samples for c#.
Thanks
Using PDF Sharp works like this:
using System;
using PdfSharp.Pdf;
using PdfSharp.Pdf.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main (string[] args)
{
Program p = new Program();
p.Test();
}
public void Test ()
{
PdfDocument document = PdfReader.Open ("Test.pdf");
document.Info.Author = "ME";
document.Save ("Result");
}
}
}
For PDFSharp:
If you would like to change/add the metadata on the Custom Properties of a PDF you can use the PdfDocument.Info.Elements object.
String filename = #"d:\temp\Hugo-input.pdf";
String outputfile = #"d:\temp\Hugo-output.pdf";
PdfDocument document = PdfReader.Open(filename);
document.Info.Elements.Add(new KeyValuePair<String,PdfItem>("/MyKey",new PdfString("MyValue")));
document.Save(outputfile);
Always start a custom key with a slash!
You can find the key and value when you open this document in Adobe Acrobat Reader -> File -> Properties -> Custom.
This works with PDFSharp 1.32
I suppose you can do it with iTextSharp.
Does the PdfDocumentInformation class from PDF Sharp fulfill your requirements.
Pimping here - my company, Atalasoft, makes .NET components for working with images. Part of the suite includes the ability to read/write PDF document metadata. It's not free, but it is run-time royalty free for desktop applications.
The code for reading is simple:
PdfDocumentMetadata metadata = PdfDocumentMetadata.FromStream(sourceStream);
to edit it and write it back to the same stream:
meta.Title = "Knicholas Knickleby";
meta.Author = "Edmund Wells";
sourceStream.Seek(0, SeekOrigin.Begin);
meta.Append(sourceStream, false); // false means don't merge - overwrite
Custom fields are supported through a hashtable.
Aspose.PDF or Aspose.PDF.Kit can do this for you.

Categories