473,394 Members | 1,737 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Adding a new MIMEType

Hello der !

at my wits end and cant figure out what is the problem..
my task is to programmatically configure IIS , part of which is to add MIMETypes...
after googling for a like a million years , found very little help with regard to this topic..finally managed to write some code but there seems to be some strange error..
following is the function..
Expand|Select|Wrap|Line Numbers
  1. long CWinWebAppController::CreateMimeType(/*[in]*/ const CMimeType& objCMimeType,
  2.                                           /*[out]*/      wstring& strErr)
  3. {
  4.   IADs*                ptrADs         = 0;
  5.   HRESULT              hr             = S_FALSE;
  6.   CComPtr<IISMimeType> ptrMimeType    = 0;
  7.  
  8.   _variant_t vntMimeMap;
  9.  
  10.  
  11.   //Reinitialise the error code
  12.   m_lError                    = 0;
  13.   m_wstrMethodName            = L"CreateMimeType";
  14.   strErr                      = SUCCESS;
  15.  
  16.  
  17.   try
  18.   {
  19.     //Get the handle to the MimeMap 
  20.     hr = ADsGetObject(L"IIS://LocalHost/MimeMap",IID_IADs,(void**) &ptrADs);
  21.     if(FAILED(hr)) 
  22.     {
  23.       strErr = ADS_GETOBJECT_FAILED;
  24.       throw hr;
  25.     }
  26.  
  27.     hr = ptrADs->QueryInterface(IID_IISMimeType, (void **)&ptrMimeType );
  28.     if(FAILED(hr)) 
  29.     {
  30.     }
  31.  
  32.     //Load the property MimeMap
  33.     hr = ptrADs->GetEx(L"MimeMap",&vntMimeMap);
  34.  
  35.  
  36.       SAFEARRAY*  pArrMimeMap ;
  37.       //point the safearray to the array inside the variant..
  38.       pArrMimeMap = vntMimeMap.parray;
  39.  
  40.       //*******************************************************
  41.       long lHigh;
  42.       SAFEARRAY * psa;    // The safearray
  43.       SAFEARRAYBOUND rgsabound[1];    // A one dimensional array
  44.       long * pData;
  45.       long lValue, lIndex;
  46.  
  47.       _variant_t vntNewMimeType;
  48.  
  49.       SafeArrayGetUBound(pArrMimeMap, 1, &lHigh);
  50.  
  51.       rgsabound[0].lLbound = 0;    // With lower bound 0;
  52.       rgsabound[0].cElements = lHigh + 1;
  53.       psa = SafeArrayCreate(VT_BSTR, 1, rgsabound);    
  54.  
  55.       //Copy the existing data into the new one...
  56.       SafeArrayCopyData(pArrMimeMap,psa);
  57.  
  58.       //set the properties of the new mimetype object...
  59.       ptrMimeType->put_Extension((_bstr_t)objCMimeType.GetMimeExtension().c_str());
  60.       ptrMimeType->put_MimeType((_bstr_t)objCMimeType.GetMimeExtension().c_str());
  61.  
  62.       //assign the mime type object to the variant...it is of type IDispatch...
  63.       vntNewMimeType.pdispVal = ptrMimeType;
  64.  
  65.       //put the variant in safe array...
  66.       lIndex = lHigh-1;
  67.  
  68.       SafeArrayPutElement(psa,&lHigh,(void*)&vntNewMimeType);
  69.  
  70.       //now return the newly created safe array in the variant...
  71.       vntMimeMap.parray = psa;
  72.  
  73.       //save the data..
  74.       hr = ptrADs->PutEx(ADS_PROPERTY_UPDATE,L"MimeMap",vntMimeMap);
  75.       if(FAILED(hr)) 
  76.       {
  77.         strErr = GRANT_BY_DEFAULT_FAILED; 
  78.         //LOG_ERROR_MESSAGE(m_wstrClassName,m_wstrMethodName,GRANT_BY_DEFAULT_FAILED);
  79.         throw hr;
  80.       }
  81.  
  82.       //********************************************************
  83.  
  84.  
  85.    }//end try
  86.   CATCH_BLOCK1(m_lError,strErr)
  87.     //delete all the pointers...
  88.   //TRACE_END(m_wstrClassName,m_wstrMethodName)
  89.   return m_lError ;
  90. }

please ignore the various variables used...thats internally used in my class...the problematic part is this line..
Expand|Select|Wrap|Line Numbers
  1. hr = ptrADs->QueryInterface(IID_IISMimeType, (void **)&ptrMimeType );
simple that this line seems, for some reason this line results in linking error with :
unresolved external symbol _IID_IISMimeType (note the extra underscore...there is no such word in any of the files...)
specifically on windows 2003 machine. it complies fine on my XP professional machine !!!
the msdn doc states all u need to do is include "IIIS.h" header file which is done , it even finds the IID in the header but failes during linking....

one whole day has been already wasted on this...can someone please tel me what goin on here ?? there is no mention of any lib as well...i thought COM usage didn require any libs to be included in the first place!!!

well the reason i need it to compile in windows 2003 machien is that thsi can only be tested on the test machine(which is 2003 machine)...my dev machien with XP doesn seem to have "properties " as an option when right click on local computer in IIS manager ....properties is required to configure MIME types...which is present in 2003 machines....not in XP...why is that so ???
Apr 2 '09 #1
0 2372

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Ryan Paul | last post by:
is there any way to determine the mimetype of a file using ruby? TIA --SegPhault
0
by: arachno | last post by:
Hello ppl, Is anyone can help me to figure out how to add data to TextML server document base? I have attached snipped, which taking XML source from file and adding it to documentbase, but my...
3
by: GR33DY | last post by:
Hello again, I can see myself becoming a regular feature at the top here ;) When I view my XML page using I.E.6 it displays fine from both my web server and when opened from windows explorer....
0
by: Alex Duggleby | last post by:
Hi everybody, I'm trying to add some mime types to the local IIS server using some c# code. The code I'm using is: ---snip--- DirectoryEntry _mimeMap =
3
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
1
by: Patrick F | last post by:
I cant figure out what mimetype .aspx pages are, i have been searching thru msdn and the only thing that i found was a way to list all mimetypes installed on the computes, output something like...
1
by: durayakar | last post by:
Hi, SQL 2005 Reporting services... I get a warning of rsInvalidMIMEType when the MIMEType of my external (http) image is Image/Jpeg or Image/JPEG... posting it here for future reference......
0
by: forge1968 | last post by:
I want to handle URLs like this on my IIS site: http://localhost/myapp/REST/foo/1 ('REST/foo/1' doesn't exist - I'll dynamically create the content). I have implemented my own...
4
by: th1421 | last post by:
Hi, I'm new to FireFox. I am currently trying to convert my website to be compatible with it. Doing so I’m trying to process some XML/XSLT pages (preferably without using JavaScript). When I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.