I have searched for this same topic and I found the solution. But the problem is the NameSpace property is giving exception. I have tried with this code :
public bool PinUnpinTaskbar(string filePath, bool pin)
{
if (!File.Exists(filePath)) throw new FileNotFoundException(filePath);
int MAX_PATH = 255;
var actionIndex = pin ? 5386 : 5387; // 5386 is the DLL index for"Pin to Tas&kbar", ref. http://www.win7dll.info/shell32_dll.html
//uncomment the following line to pin to start instead
//actionIndex = pin ? 51201 : 51394;
StringBuilder szPinToStartLocalized = new StringBuilder(MAX_PATH);
IntPtr hShell32 = LoadLibrary("Shell32.dll");
LoadString(hShell32, (uint)actionIndex, szPinToStartLocalized, MAX_PATH);
string localizedVerb = szPinToStartLocalized.ToString();
string path = Path.GetDirectoryName(filePath);
string fileName = Path.GetFileName(filePath);
// create the shell application object
//var shell = new Shell32.Shell();
dynamic shellApplication = Activator.CreateInstance(Type.GetTypeFromProgID("Shell.Application"));
dynamic directory = shellApplication.NameSpace(path);
dynamic link = directory.ParseName(fileName);
dynamic verbs = link.Verbs();
for (int i = 0; i < verbs.Count(); i++)
{
dynamic verb = verbs.Item(i);
if (verb.Name.Equals(localizedVerb))
{
verb.DoIt();
return true;
}
}
return false;
}
But the problem is with shellApplication.Namespace(path) here. It can not find such property/Method. I don't have too much idea on this. So, any kind of help will be appreciated.
Related
I need suggestion on getting a list of PDF files from the external storage in android device
1.You could traverse the folder and filter the PDF files:
public void Search_Pdf_Dir(File dir)
{
string pdfPattern = ".pdf";
File[] FileList = dir.ListFiles();
if (FileList != null)
{
for (int i = 0; i < FileList.Length; i++)
{
if (FileList[i].IsDirectory)
{
Search_Pdf_Dir(FileList[i]);
}
else
{
if (FileList[i].Name.EndsWith(pdfPattern))
{
//here you have that file.
}
}
}
}
}
then you could call like Search_Pdf_Dir(Android.OS.Environment.ExternalStorageDirectory);
2.use MediaStore - Uri to query all types of files :
ContentResolver cr = ContentResolver;
Android.Net.Uri uri = MediaStore.Files.GetContentUri("external");
// every column, although that is huge waste, you probably need
// BaseColumns.DATA (the path) only.
string[] projection = null;
string selectionMimeType = MediaStore.Files.FileColumns.MediaType + "=?";
string mimeType = MimeTypeMap.Singleton.GetMimeTypeFromExtension("pdf");
string[] selectionArgsPdf = new string[] { mimeType };
string sortOrder = null;
var allPdfFiles = cr.Query(uri, projection, selectionMimeType, selectionArgsPdf, sortOrder);
while (allPdfFiles.MoveToNext())
{
int column_index = allPdfFiles.GetColumnIndexOrThrow(MediaStore.Images.Media.InterfaceConsts.Data);
string filePath = allPdfFiles.GetString(column_index);//the pdf path
}
According to this post, you can make Visual Studio find.
I update the code of Asif Iqbal K from the article a bit to eliminate build error.
public const string vsWindowKindFindResults1 = "{0F887920-C2B6-11D2-9375-0080C747D9A0}";
public string FindInFiles(string searchText)
{
EnvDTE80.DTE2 dte;
dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
dte.MainWindow.Activate();
EnvDTE.Find find = dte.Find;
find.Action = EnvDTE.vsFindAction.vsFindActionFindAll;
find.FindWhat = searchText;
find.MatchWholeWord = false;
find.ResultsLocation = EnvDTE.vsFindResultsLocation.vsFindResults1;
find.Target = EnvDTE.vsFindTarget.vsFindTargetSolution;
find.PatternSyntax = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
find.SearchSubfolders = true;
var x = dte.Find.FindWhat;
EnvDTE.vsFindResult result = find.Execute();
var findWindow = dte.Windows.Item(vsWindowKindFindResults1);
string data = "";
System.Threading.Thread.Sleep(5000);//Comment out this code to see the problem, this line of code is not the solution though.
if (result == EnvDTE.vsFindResult.vsFindResultFound)
{
var selection = findWindow.Selection as EnvDTE.TextSelection;
selection.SelectAll();
data = selection.Text;
}
return data;
}
I see that the problem is the function return the string (string data) too early, so it can't get all the text from the result window.
So the code comes so close to get the find text. One remaining puzzle is to check if the find process complete, then get the text.
So the question is: replace what code with the code
System.Threading.Thread.Sleep(5000);
So that the function FindInFiles() can get all the text of 'FindResult 1" window.
Thanks for reading.
Here is the solution
EnvDTE80.DTE2 s_dte;
EnvDTE.FindEvents s_findEvents;
public const string vsWindowKindFindResults1 = "{0F887920-C2B6-11D2-9375-0080C747D9A0}";
public frmFindHelper()
{
InitializeComponent();
s_dte = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE");
s_dte.MainWindow.Activate();
s_findEvents = s_dte.Events.FindEvents;
s_findEvents.FindDone += new EnvDTE._dispFindEvents_FindDoneEventHandler(OnFindDone);
}
private void OnFindDone(EnvDTE.vsFindResult result, bool cancelled)
{
if (result == EnvDTE.vsFindResult.vsFindResultFound)
{
var findWindow = s_dte.Windows.Item(vsWindowKindFindResults1);
string data = "";
var selection = findWindow.Selection as EnvDTE.TextSelection;
selection.SelectAll();
data = selection.Text;
MessageBox.Show("Done!");
}
}
private void btnFind_Click(object sender, EventArgs e)
{
EnvDTE.Find find = s_dte.Find;
find.Action = EnvDTE.vsFindAction.vsFindActionFindAll;
find.FindWhat = txtSearch.Text;
find.MatchWholeWord = false;
find.ResultsLocation = EnvDTE.vsFindResultsLocation.vsFindResults1;
find.Target = EnvDTE.vsFindTarget.vsFindTargetSolution;
find.PatternSyntax = EnvDTE.vsFindPatternSyntax.vsFindPatternSyntaxRegExpr;
find.SearchSubfolders = true;
var x = s_dte.Find.FindWhat;
EnvDTE.vsFindResult result = find.Execute();
}
Thanks to Ed Dore from this post
I'm trying to convert a bit of VBA (outlook) to c# for an addin. Struggling with it. The code changes the account dropdown on the reply/replyall/forward form in outlook. Now I have to type more useless stuff because the editor is moaning about more code than text. I have converted 99% of it.
public string Set_Account(string AccountName, Outlook.MailItem M)
{
string tempSet_Account = null;
Outlook.Inspector OLI = null;
string strAccountBtnName = null;
int intLoc = 0;
const int ID_ACCOUNTS = 31224;
Office.CommandBars CBs = null;
Office.CommandBarPopup CBP = null;
Office.CommandBarControl MC = null;
M.Display();
OLI = M.GetInspector;
if (OLI != null)
{
CBs = OLI.CommandBars;
CBP = CBs.FindControl(, ID_ACCOUNTS); // This line errors and I can't find what goes in it to make it work
CBP.Reset();
if (CBP != null)
{
foreach (Office.CommandBarControl MCWithinLoop in CBP.Controls)
{
MC = MCWithinLoop;
intLoc = MCWithinLoop.Caption.IndexOf(" ") + 1;
if (intLoc > 0)
{
strAccountBtnName = MCWithinLoop.Caption.Substring(intLoc);
}
else
{
strAccountBtnName = MCWithinLoop.Caption;
}
if (strAccountBtnName == AccountName)
{
MCWithinLoop.Execute();
tempSet_Account = AccountName;
break;
}
}
}
}
tempSet_Account = "";
MC = null;
CBP = null;
CBs = null;
OLI = null;
return tempSet_Account;
}
I am having trouble with this line specifically:
CBP = CBs.FindControl(, ID_ACCOUNTS);
It fails and says it needs a type "MsoControlType" but I cannot find any control type that fits. It seems in VBA you can findcontrol with just one entry (the other being blank) In C# you need 2. Every thing I put it the compiler moans about
cannot convert Microsoft.Office.Core.MsoControlType.msoCommandBarControl to ...msoCommandBarPopup
But I cannot find a reference to it anywhere.
In C#, you can't leave out a parameter like you're doing here: ".FindControl(,". If you have to pass "null" or a null object.
I need to download JPG file from FileCabinet in NetSuite. For that I know the file name, so I searched file and assigned to FileObject. I got the object right, but got NULL content. I am providing here some code. Can anybody point out the error or any missing step here? Thank you.
var result = _service.search(flSearch);
if (result.totalRecords > 0)
{
recordList = result.recordList;
Record[] records = new Record[recordList.Length];
for (int j = 0; j < recordList.Length; j++)
{
if (recordList[j] is File)
{
File itemImage = (File)(recordList[j]);
byte[] data;
data = new Byte[(int)itemImage.fileSize];
data = itemImage.content; //Here getting NULL value
FileStream inFile;
using (inFile = new FileStream("newImage.jpg", FileMode.Create, FileAccess.Write))
{
inFile.Write(data, 0, data.Length);
}
}
}
}
itemImage is just a string - base64.
take that string and do a base64 decode and save that to your local file.
If the search is based on the internal id of the file you want to search, then the following code may help
var service = LoginNetSuite();
Tuple<string, string> fileContent = null;
FileSearch fileSearch = new FileSearch();
FileSearchBasic fileSearchBasic = new FileSearchBasic();
// Specify the folder in which the search is to be done.
SearchMultiSelectField folderFilter = new SearchMultiSelectField();
folderFilter.#operator = SearchMultiSelectFieldOperator.anyOf;
folderFilter.operatorSpecified = true;
RecordRef[] folder = new RecordRef[1];
folder[0] = new RecordRef();
folder[0].internalId = "78990"; // 78990 => Internal id of the folder.
folderFilter.searchValue = folder;
fileSearchBasic.folder = folderFilter;
// Specify the file internal id.
SearchMultiSelectField fileFilter = new SearchMultiSelectField();
fileFilter.#operator = SearchMultiSelectFieldOperator.anyOf;
fileFilter.operatorSpecified = true;
RecordRef[] rec = new RecordRef[1];
rec[0] = new RecordRef();
rec[0].internalId = "345656"; // 345656 => Internal id of the file.
fileFilter.searchValue = rec;
fileSearchBasic.internalId = fileFilter;
fileSearch.basic = fileSearchBasic;
var result = service.search(fileSearch);
var recordList = (Record[])result.recordList;
if (recordList != null && recordList.Length != 0)
{
var file = (File)result.recordList.First();
fileContent = new Tuple<string, string>(file.url, file.name);
}
In this code the folder internal id and the file internal id is given as the search parameters. So the file search will be done in the specified file cabinet with specified file id.
The response from netsuite will consist of the internal id, file name, url, folder name etc. The file can be downloaded from the url location.
I am trying to set the Template property in the Summary Information Stram but whatever I do, it fails. I can read the property from the handle but can't write it back.
I want to generate multilingual copies of the MSI which is built (candled and light) in English. I am able to replace all the respective translated data in all the tables; the only thing I can not change is the Template property above.
I have tried all the ways I can use to pass the new String value, but it always says invalid parameter.
Here's the function I am using to do the same (C#):
public Boolean ChangeTemplateSummaryProperty(String strLangID) {
IntPtr hSIHandle;
if (MsiError.Success == MsiInterop.MsiGetSummaryInformation(IntPtr.Zero, m_strMSIPath, 1, out hSIHandle))
{
VariantType vtType = VariantType.LPStr;
int iVal = 0;
FILETIME oFileTime;
oFileTime.HighDateTime = 0;
oFileTime.LowDateTime = 0;
int iValSz = 0;
MsiError err = MsiInterop.MsiSummaryInfoGetProperty(hSIHandle, (uint)(SummaryInformationStreamProperty.Template),
out vtType, out iVal, out oFileTime, String.Empty, ref iValSz);
String strValue = new String('l', ++iValSz);
if (err == MsiError.MoreData)
{
err = MsiInterop.MsiSummaryInfoGetProperty(hSIHandle, (uint)(SummaryInformationStreamProperty.Template),
out vtType, out iVal, out oFileTime, strValue, ref iValSz);
}
else
{
Logger.LogError("Failed to get SummaryInformationStreamProperty.Template... err = " + err);
}
//I get the correct value here. as ";1033\0"
Logger.LogInfo("SummaryInformationStreamProperty.Template: " + strValue);
char[] arrNV = new char[strLangID.Length+2];
arrNV[0] = ';';
for (int i = 1; i < strLangID.Length + 1; i++) {
arrNV[i] = strLangID[i-1];
}
arrNV[strLangID.Length+1] = '\0';
String strNewVal = new String(arrNV);
//tried this, but fails.
//string strNV = ";";
//string strNV2 = strNV.Insert(1, strLangID);
//strNV2 = strNV2.Insert(strLangID.Length + 1, "\0");
err = MsiInterop.MsiSummaryInfoSetProperty(hSIHandle, (uint)(SummaryInformationStreamProperty.Template),
vtType, iVal, oFileTime, strNewVal);
if (err != MsiError.NoError)
{
Logger.LogError("Failed to set SummaryInformationStreamProperty.Template... err = " + err);
MsiInterop.MsiSummaryInfoPersist(hSIHandle);
MsiInterop.MsiCloseHandle(hSIHandle);
return false;
}
MsiInterop.MsiSummaryInfoPersist(hSIHandle);
MsiInterop.MsiCloseHandle(hSIHandle);
}
else
{
Logger.LogError("Failed to MsiGetSummaryInformation...");
return false;
}
return true;
}
Get rid of the MsiInterop that you are using and use the interop found in WiX's DTF. The Microsoft.Deploymnet.WindowsInstaller namespace has a SummaryInformation Class that exposes a read/write string Template property. Way better object model and interop without worrying about all the P/Invoke details that your current interop makes you deal with.
I'm home now so here's a code snippet:
using Microsoft.Deployment.WindowsInstaller;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using( var database = new Database(#"C:\orca.msi", DatabaseOpenMode.Direct ))
{
database.SummaryInfo.Template = "Intel;666";
}
}
}
}
Notice the use of the using() clause. The Database class implements the IDisposable interface and automatically handles ( pun intended ) cleaning up all those pesky unmanaged handles for you.
Database msidb = objInstaller.OpenDatabase(MSIFileNameWithPath,MsiOpenDatabaseMode.msiOpenDatabaseModeTransact);
SummaryInfo info = msidb.get_SummaryInformation(1);
info.set_Property(2, (object)("sample title"));
info.Persist();
msidb.Commit();
The best reference to answer this is in detail is
https://learn.microsoft.com/en-us/archive/blogs/mwade/sail-away-with-me-to-another-world