data file: how to start its application

Hello! I have a byte array in memory for a file and also its filename 
(actually a mail attachment). Now I want to "open" this file. In case of a 
"*.doc" file I have to find the association (winword), run that program and 
give it a path to my memory or something like that.
I think the simplest way to achieve this is to save the data into a temp 
file (GetTempPath + actual file name, overwriting any previous one), and 
then running RunCmd somehow and Windows knows what to do. I know how to 
write the file, but a RunCmd command doesn't exist or I haven't found 
something like that in Win32 API or MFC. Any ideas?
Eric


0
bauersachs (33)
2/2/2007 3:08:49 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
1247 Views

Similar Articles

[PageSpeed] 48

Eric wrote:

> Hello! I have a byte array in memory for a file and also its filename 
> (actually a mail attachment). Now I want to "open" this file. In case of a 
> "*.doc" file I have to find the association (winword), run that program and 
> give it a path to my memory or something like that.
> I think the simplest way to achieve this is to save the data into a temp 
> file (GetTempPath + actual file name, overwriting any previous one), and 
> then running RunCmd somehow and Windows knows what to do. I know how to 
> write the file, but a RunCmd command doesn't exist or I haven't found 
> something like that in Win32 API or MFC. Any ideas?
> Eric
> 
> 

Eric:

ShellExecute()
ShellExecuteEx()
CreateProcess()

If the file type is registered to the application, you do not need to 
use the executable name.

David Wilkinson
0
no-reply8010 (1791)
2/2/2007 3:44:40 PM
How about

ShellExecute(m_hWnd,"open",TheFile,NULL,NULL,SW_SHOWNORMAL);

Actually that was all mail programs do. When you want to open an attachment 
they save it somewhere and then open it.  They usually don't overwrite a 
file if there is one with the same name, they usually add a number to the 
end.

AliR.

"Eric" <bauersachs@kull.ch.cuthere.nospam.me.com> wrote in message 
news:uYtnkwtRHHA.2124@TK2MSFTNGP06.phx.gbl...
> Hello! I have a byte array in memory for a file and also its filename 
> (actually a mail attachment). Now I want to "open" this file. In case of a 
> "*.doc" file I have to find the association (winword), run that program 
> and give it a path to my memory or something like that.
> I think the simplest way to achieve this is to save the data into a temp 
> file (GetTempPath + actual file name, overwriting any previous one), and 
> then running RunCmd somehow and Windows knows what to do. I know how to 
> write the file, but a RunCmd command doesn't exist or I haven't found 
> something like that in Win32 API or MFC. Any ideas?
> Eric
>
> 


0
AliR3470 (3235)
2/2/2007 3:45:58 PM
It exists.  You should look at ShellExecute(Ex)().

Hope it helps.

Saul775

"Eric" wrote:

> Hello! I have a byte array in memory for a file and also its filename 
> (actually a mail attachment). Now I want to "open" this file. In case of a 
> "*.doc" file I have to find the association (winword), run that program and 
> give it a path to my memory or something like that.
> I think the simplest way to achieve this is to save the data into a temp 
> file (GetTempPath + actual file name, overwriting any previous one), and 
> then running RunCmd somehow and Windows knows what to do. I know how to 
> write the file, but a RunCmd command doesn't exist or I haven't found 
> something like that in Win32 API or MFC. Any ideas?
> Eric
> 
> 
> 
0
Saul775 (62)
2/2/2007 3:47:01 PM
You have to put the byte array out into the file system and give it a name, as you
describe.  Note that you can GetTempFileName and it guarantees that it will not overwrite
any existing instance.  Then just call ShellExecute on the filename.  If it is a .doc
file, Word (or WordPad, if Office isn't installed) will be invoked.  I have no idea what a
RunCmd is.
				joe

On Fri, 2 Feb 2007 16:08:49 +0100, "Eric" <bauersachs@kull.ch.cuthere.nospam.me.com>
wrote:

>Hello! I have a byte array in memory for a file and also its filename 
>(actually a mail attachment). Now I want to "open" this file. In case of a 
>"*.doc" file I have to find the association (winword), run that program and 
>give it a path to my memory or something like that.
>I think the simplest way to achieve this is to save the data into a temp 
>file (GetTempPath + actual file name, overwriting any previous one), and 
>then running RunCmd somehow and Windows knows what to do. I know how to 
>write the file, but a RunCmd command doesn't exist or I haven't found 
>something like that in Win32 API or MFC. Any ideas?
>Eric
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15972)
2/2/2007 4:03:16 PM
The API function ShellExecute did the trick.

Eric

"Eric" <bauersachs@kull.ch.cuthere.nospam.me.com> wrote in message 
news:uYtnkwtRHHA.2124@TK2MSFTNGP06.phx.gbl...
> Hello! I have a byte array in memory for a file and also its filename 
> (actually a mail attachment). Now I want to "open" this file. In case of a 
> "*.doc" file I have to find the association (winword), run that program 
> and give it a path to my memory or something like that.
> I think the simplest way to achieve this is to save the data into a temp 
> file (GetTempPath + actual file name, overwriting any previous one), and 
> then running RunCmd somehow and Windows knows what to do. I know how to 
> write the file, but a RunCmd command doesn't exist or I haven't found 
> something like that in Win32 API or MFC. Any ideas?
> Eric
>
> 


0
bauersachs (33)
2/2/2007 4:25:08 PM
Wow! So many answers in such a short time (haven't seen them before posting 
my own answer). Thanks to all. Some comments:
@Joseph: RunCmd is probably from VB or Access or so.
If I use GetTempFilename then I have a .tmp file and cannot start the right 
application. Therefore I prefer to keep the filename and overwrite the 
existing one (if it exists). Of course renaming it to 1,2,3, etc. would be 
better, but there's no more budget to continue here.
I've used SW_SHOW instead of SW_SHOWNORMAL. It works, although probably not 
correct according to the documentation.
Thanks to all!
Eric


0
bauersachs (33)
2/2/2007 4:37:02 PM
Reply:

Similar Artilces:

horizontal data to vertical data
I have a set of data list in the horizontal manner. Is there a macro that can send this data vertically instead of manually doing it? Thanks in advance. Aloysicus One way .. Assume source data is in Sheet1, A1:E1 In Sheet2 Put in A1: =OFFSET(Sheet1!$A$1,COLUMNS($A$1:A1)-1,ROWS($A$1:A1)-1) Copy A1 down by as many rows as there are columns in Sheet1, i.e. down to A5 A1:A5 will return whats in A1:E1 in Sheet1 -- Rgds Max xl 97 --- GMT+8, 1� 22' N 103� 45' E xdemechanik <at>yahoo<dot>com ---- "Aloysicus" <aloy33@singnet.com.sg> wrote in message ne...

Excel 2007
When files are already open by another user, we have found that only users with Administrator permissions on their computers are able to open files read-only. If the user only has basic user permissions they receive a message stating the file could not be found. This was not a problem with Office 2000 (which we recently upgraded from). Any ideas? Thanks, Chris ...

Difficulty Aligning Series Data With Proper Dates
I ‘m building a column graph using Excel 2007 and I’m having difficulty aligning a series of data with the proper dates. I have 2 series of data – Series 1: Includes a value for each quarter in 2009 (e.g., Mar-09, Jun-09, etc). Series 2: Includes a value for each quarter in 2010 (e.g., Mar-10, Jun-10, etc). After creating each series, I select the appropriate dates (Series 1 – 2009 dates / Series 2 – 2010 dates). The first issue that I’m having is that when I select the second set of dates (for Series 2), it overrides the first – so the x-axis initially shows 2009 dates, but then ...

export public folder data?
Am in the process of performing an Alternate server recovery of an Exchange 2003 Information Store. The reason being that on the current server all the email has dissappeared from the public folder mail folders...its a very strange situation indeed. Hoping that by restoring an earlier backup to a different machine we can see if the emails will return. If they do, is there a way I could export the contents of these folders back into the current info store? I gather that Exmerge will only work on Mailboxes and not Public Folders... Many thanks in advance, Neil On Fri, 19 Aug 2005 08:58...

storing read only data
I work for a powder coating company and want to make a program that will store all of the data on each part. I want to be able to go to the computer type in a part number and retrieve all of the data for that part. It has to be read onlyso that it can only be edited by a supervisor. I was told i could use excel for this and an "at" function was mentioned. thank you If the info fits in 256 columns, you can put the part number in column A and the info in B:IV. Then apply data|filter|autofilter and use that to just show the parts you want. If the data is more than 256 columns, you co...

How to organize data?
I am a frustrated Excel newbie. I grit my teeth every time I have to use Excel. But I need to create a small database of records and chart it's monthly progression, and I think Excel is probably the best program for the job. Only, I don't know who to do this. Please bear with me as I really need help with this. Say that I have a short list of vendors in different cities. For each vendor I have a total # of items in their inventory and another # of the # of items sold from the inventory, and a percentage of that. So I have the vendors listed in Column A. # of items in inventory ...

importing an .ost file to OL2007
Hi, I was using Outlook 2003 at my previous employer on a MS Exchange server. Before I left I backed up my .ost file and .pst files. I am running Outlook 2007 at home and am trying to work out how to open the ..ost folder. It appears to only be looking for .pst files. Can anyone help please? You cannot Maybe find a third party who will convert for you "Tim123" <Tim123@discussions.microsoft.com> wrote in message news:8D9F4666-0CA7-4C08-9FE2-5892B0CB5E11@microsoft.com... > Hi, I was using Outlook 2003 at my previous employer on a MS Exchange > server. > Before I ...

Errors in application log at the begining of backups
I am getting the following error messages at the begining of our backup rotation every day since the server was stood up (error at the end of this thread). The system is an Exchange 2003 SP1 sitting on Windows 2003 (not sp1). This system only houses mailboxes (no Public folders). The backup is veritas netbackup 4.5. The backup completes successfully about 3 hours later and all log files are deleted as expected. Any thoughts? Event Type: Error Event Source: ESE BACKUP Event Category: Callback Event ID: 904 Date: 10/12/2005 Time: 11:08:47 PM User: N/A Computer: EATL0MS203 Descriptio...

file names in excel
When I try to name a file all I get saved is the first letter of the title I have entered. What is set wrong? Doesn't sound right. Show us the code that you use. -- HTH Bob Phillips "TonyB" <TonyB@discussions.microsoft.com> wrote in message news:4BCC8463-39BE-40D2-84C4-44311DEE14FA@microsoft.com... > When I try to name a file all I get saved is the first letter of the title I > have entered. > > What is set wrong? WinXP? Check to see if Excel is running in Windows 95 compatibility mode. There was a post that said: When I disabled compatibility mode...

Selecting specific data #2
Hi everyone I have another little problem. I have got a list of 20 items on sheet1, Cells A1 - A20 (numbered 1 - 20) and Cells B1 - B20 are items relating to that number, ie, number 1 = Concrete, number 2 = walls, and so on. Now on sheet 2 I have a table, again cell range A1:B20. I would like to know a formula so that when I enter a number in to column A, the corresponding item to that number appears in column B. ie, if I enter number 8 in Cell A1 on sheet 2, then I would like Floor to appear in Cell B1. Does this make sense? -- Thanks in advance for your help Lee Hi Lee Data range i...

Unable to open Excel file #4
Error message: File cannot be accessed. The file may be read-only, or you may be trying to access a read-only location. Or, the server the document is stored on may not be responding. The file was not saved as read-only and the file is on a diskette. Sounds like a bad disk. Copy the disk to the hard drive somewhere an try to open there. -- kkkni ----------------------------------------------------------------------- kkknie's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=754 View this thread: http://www.excelforum.com/showthread.php?threadid=26520 Vic Cop...

"external data sources" and "external data ranges"
what is the difference between these? i have run the vb macro code on http://support.microsoft.com/kb/330383 to check if i have any external data sources or data ranges but there are none. the reason i need to know is becuase i'm working with office sharepoint server 2007 and i cannot access a file thru the web access web part because it says: "The workbook that you selected cannot be loaded because it contains the following features that are not supported by Excel Services: External data ranges (also called query tables)" anyone? thanks ...

Saving sheet to text file
Hi, Can someone please help me with a date formatting problem. When I save a sheet to a TXT file manually (using the SaveAs option, etc.), I have no problems and the dates remain as they are shown on the sheet as d/m/yy (eg 15/9/05), but when I use the following macro, the dates on that sheet are saved to the text file as month/day/year (eg 9/15/05) Sub ExportToMYOB() ActiveWorkbook.Save Sheet2.SaveAs Filename:="C:\Premier9\Data files\ExportToMYOB.txt", _ FileFormat:=xlText, CreateBackup:=False ActiveWindow.Close End Sub Why is it so? Rob How did you ve...

What was your data migration experience for MS CRM 3.0?
Has anyone used DMF 3.0 to migrate data into CRM using its wizards or stored proceedures? What happened and how did you do it? Andy It's a bit unwieldy, but if you follow the documentation closely and do thorough tests it is a helpful tool. You should be prepared to do some extensive data cleansing and search the newsgroups when you hit a roadblock. -- Matt Wittemann, CRM MVP http://icu-mscrm.blogspot.com "Andy" wrote: > Has anyone used DMF 3.0 to migrate data into CRM using its wizards or > stored proceedures? > > What happened and how did you do it? >...

Last Column With Data
How do I check a certain row to find out the last column in the row that has data? Dim myRow as long dim LastCol as long myrow = 1243 with worksheets("SomeSheetnamehere") lastcol = .cells(myrow,.columns.count).end(xltoleft).column end with msgbox LastCol This will break if you've used the last column in that row -- or if you haven't used any cells in that row. Is that a problem? Bishop wrote: > > How do I check a certain row to find out the last column in the row that has > data? -- Dave Peterson This gives a interger...

Sum of cells in column if data in cells = specific value
In column K, I have different information. Each cell either says "Returned" or "Disposed." In K35, I would like to have a total of all the cells in the column which show "Returned" and in K36, I would like to have a total of all the cells in the column whith show "Disposed" Thanks Please don't multipost. In article <c7o4m5$jp7$1@titan.btinternet.com>, "That's Confidential" <joebloggs@hotmail.com> wrote: > In column K, I have different information. Each cell either says "Returned" > or "Disposed...

Presenting Pivot table data as product of 2 source data columns
I have the following data F1 F2 D1 D2 F01 1 10 1 F02 2 20 3 F01 2 30 6 F01 5 40 4 F02 6 40 5 F1 to be presented in rows F2 to be presented in columns D1* D2 to be presented as data Is that possible without defining an extra column in my source data? regards, Louis Louise - Yes, it's a calculated pivottable field. Once you have the pivottable established except for the data values, select Options tab, Formulas drop down arrow, calculated field. "loconel" wrote: > > I have the following data > > F1 F2 D1 D2 > F01 1 10 1 > F02 2 20 3 > F01 2 30 6 >...

2003 files not looking right in 2007
I opened a brochure in 2007 I just completed last week using 2003. Whew, it was a mess. Spacing wrong etc. I went to another computer and using 2003 opened it and it was fine. Why is this? I have to almost redo the whole brochure if I am going to use it in 2007. Am I missing something. Thanks Different printer? -- JoAnn Paules MVP Microsoft [Publisher] ~~~~~ How to ask a question http://support.microsoft.com/KB/555375 "Pam" <Pam@discussions.microsoft.com> wrote in message news:C260E80A-0B9E-4965-AFFB-8DB24DF05B32@microsoft.com... >I opened a brochure in 200...

.NET & XSLT: Unwanted namespace in resulting file after using extension objects
Hello, after using extension objects in the stylesheets there's an additional namespace entry in the resulting file. How can I prevent that? See: ..NET/C#: XslCompiledTransform xslt = new XslCompiledTransform(); .... XsltArgumentList xsltArgs = new XsltArgumentList(); xsltArgs.AddExtensionObject("ibd:DanTe", this); .... xslt.Transform( _source, xsltArgs, target ); XSLT: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/ Transform" xmlns:ibd="ibd:DanTe"> &l...

data file: how to start its application
Hello! I have a byte array in memory for a file and also its filename (actually a mail attachment). Now I want to "open" this file. In case of a "*.doc" file I have to find the association (winword), run that program and give it a path to my memory or something like that. I think the simplest way to achieve this is to save the data into a temp file (GetTempPath + actual file name, overwriting any previous one), and then running RunCmd somehow and Windows knows what to do. I know how to write the file, but a RunCmd command doesn't exist or I haven't found some...

merging data
I have a master file and 4 workbooks where individuals enter info daily. I need to update the master file workbook at the end of the day with the info from the 4 individual notebooks. How would I merge this data? I tried the "shared workbooks" process but it wouldn't let me do it. Please Help! Since your question is very "general", here's a "general" suggestion: Explore the use of links. Have all WBs open. Right click in a pertinent data cell of one of the 4 WBs, and choose "Copy". Navigate to the appropriate cell in the "Master&quo...

Scanning website files on the fly
Hi folks, One of my websites got infected with a virus and was blocked by Google. I stumbled across this page and it really helped me getting the problem solved very quickly without having to reupload my website from my computer. I can't paste the whole method here because it's explained in pictures. Check out: http://www.orioncities.com/scanning-website-files-for-malware-and-viruses I hope this will help someone. Their are many well known and known to be good sites, that will help others with malware and virus infection, I wouldn't click on any link inclu...

Vertical Data Extraction
Hi, I need to create a chart that is based on changing values. The Values are all stored vertically in a Worksheet called Percentage. The chart sheet contains a selection box where the user can select a specific search and a date and the selected conditions should be searched for and the chart should display results. Basically, when the user selects X in the first list box and Y in the second one, the code should search the Percentage worksheet for all instances of value=x and y and output. column Row Feature1 Feature2 Feature3 2000 0.5 8.3 10 2000 ...

Saving a Excel 97 file into Excel 2003 file
There is no problem in opening a Excel97 file into Excel 2003. The problem occurs when trying to perform "Save As" after that. The error message is "Excel cannot complete this task with available resources. Choose less data or close other applications." The file is only about 2.5MB and there is no other applications running in the background except the normal firewall and antivirus programs. The interesting thing about this problem is that, it occurs on one PC and not on another? Both PC got 512MB DDR Ram and plenty of space in hard drives. The total paging s...

Write Hex to Output File in MFC
Hi All: I need to generate a file using MFC which is Unicoded. In other words, I need to have a file that has '16-bit hex coding' showing in the file when I open it thru notepad Problem: Even though I store the string in 16-bit format, when I write it into the file, it still displays it as ascii. I need to see '16-bit Hex' instead of the ascii. I am using the following code. The output in the file is "hello". Instead, I want to see "0x0048 0x0065 0x006C 0x006C 0x006F". I am using the following code. wchar_t rashid2[] =_T(L"Hello"); HAND...