ThinkGeo.com    |     Documentation    |     Premium Support

Change file name

Hello all,


I want to recreate my .shp file name, because I don't let my customer know which data format I use.


So, could you help me to solve this problem?


for example, road layer contains five different extension name (road.shp, road.shx, road.dbf, road.idx, road.ids)


how could i to modify its extension  names and I still can read it by your component?ex. road.shp→road.aa, road.shx→road.bb, road.dbf→road.cc, road.idx→road.dd...etc


  ShapeFileFeatureLayer Road_02= new ShapeFileFeatureLayer("road.aa",  "road_02.dd");


 



Carol,


I am not sure why you want to hide the extension, while following code can help you somehow if you can hide the event codeJ. Here, aa is just a random name you can give, .ab1 --- .shp file
.ab2 --- .shx file
.ab3---- .dbf file
.ab4---- .idx file
.ab5---- .ids file

 

private void LoadAMapFromStreams_Load(object sender, EventArgs e)
        {
            winformsMap1.MapUnit = GeographyUnit.DecimalDegree;
            winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
 
            //WorldMapKitWmsDesktopOverlay worldMapKitDesktopOverlay = new WorldMapKitWmsDesktopOverlay();
            //winformsMap1.Overlays.Add(worldMapKitDesktopOverlay);
 
            ShapeFileFeatureLayer shapeFileLayer = new ShapeFileFeatureLayer(@"C:\DoesNotExistDirectory\aa");
            ((ShapeFileFeatureSource)shapeFileLayer.FeatureSource).StreamLoading += new EventHandler<StreamLoadingEventArgs>(LoadAMapFromStreams_StreamLoading);
            shapeFileLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.CreateSimpleAreaStyle(GeoColor.SimpleColors.Transparent, GeoColor.FromArgb(100, GeoColor.SimpleColors.Green));
            shapeFileLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20;
 
            LayerOverlay staticOverlay = new LayerOverlay();
            staticOverlay.Layers.Add("WorldLayer", shapeFileLayer);
            winformsMap1.Overlays.Add(staticOverlay);
 
            winformsMap1.CurrentExtent = new RectangleShape(-139.2, 92.4, 120.9, -93.2);
            winformsMap1.Refresh();
        }
 
        private void LoadAMapFromStreams_StreamLoading(object sender, StreamLoadingEventArgs e)
        {
            string extension = Path.GetExtension(e.AlternateStreamName);
 
            if (string.Equals(extension, string.Empty))
            {
                e.AlternateStream = new FileStream(@"..\Post7307\Countries02.ab1", e.FileMode, e.FileAccess);
            }
 
            if (string.Equals(extension, ".shx"))
            {
                e.AlternateStream = new FileStream(@"\Post7307\Countries02.ab2", e.FileMode, e.FileAccess);
            }
 
            if (string.Equals(extension, ".dbf"))
            {
                e.AlternateStream = new FileStream(@"\Post7307\Countries02.ab3", e.FileMode, e.FileAccess);
            }
 
            if (string.Equals(extension, ".idx"))
            {
                e.AlternateStream = new FileStream(@"\Post7307\Countries02.ab4", e.FileMode, e.FileAccess);
            }
 
            if (string.Equals(extension, ".ids"))
            {
                e.AlternateStream = new FileStream(@"\Post7307\Countries02.ab5", e.FileMode, e.FileAccess);
            }
        }


Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Thanks for your help, Yale


but it works wrong. error message: OleDbException:  Microsoft Jet database engine can not find 'aa' object. Make sure the object exists, and you have not misspelled the object name and path


string sSql = "SELECT TOP  10 * FROM aa WHERE ROADNAME Like '%" abc"%'";


 ShapeFileFeatureSource aa_Layer = new ShapeFileFeatureSource(@"D:\aa.a4");  // aa.a4>> aa.shp

 aa_Layer.StreamLoading += new EventHandler<streamloadingeventargs></streamloadingeventargs>(LoadAMapFromStreams000_StreamLoading);


            aa_Layer.Open();

            aa_DT = road_Layer.ExecuteQuery(sSql);

            aa_Layer.Close();


  private void LoadAMapFromStreams000_StreamLoading(object sender, StreamLoadingEventArgs e)

        {

            string extension = Path.GetExtension(e.AlternateStreamName);


            if (string.Equals(extension, ".dbf"))

            {

                e.AlternateStream = new FileStream(@"D:\aa.a1", e.FileMode, e.FileAccess);

            }


            if (string.Equals(extension, ".ids"))

            {

                e.AlternateStream = new FileStream(@"D:\aa.a2", e.FileMode, e.FileAccess);


            }


            if (string.Equals(extension, ".idx"))

            {

                e.AlternateStream = new FileStream(@"D:\aa.a3", e.FileMode, e.FileAccess);


            }


            if (string.Equals(extension, ".shp"))

            {

                e.AlternateStream = new FileStream(@"D:\aa.a4", e.FileMode, e.FileAccess);


            }


            if (string.Equals(extension, ".shx"))

            {

                e.AlternateStream = new FileStream(@"D:\aa.a5", e.FileMode, e.FileAccess);


            }

        }



Carol, 
  
 Thanks for your reply. 
  
 Before we are going further, just make sure this problem will only happens when the SQL statement is excuted? It should be ok when displaying the Map control. 
  
 Any more info would be appreciated. 
  
 Thanks. 
  
 Yale 


Hello, Yale 
  
 if i just display map, it works well. 
 but if i execute … 
 aa_DT = road_Layer.ExecuteQuery(sSql); 
 it will happen error. 
  
 I don’t know where has wrong! 
  
 I have to solve this problem in hurry. :( 


Carol, 
  
 I am sorry to say that this problem may be a bit difficult to solve, one possible solution is to write your own SQL executing logic by calling the OLEDB directly. I remember there is some sample code for this in the forum, while I cannot find it in a short time. 
  
 Just let you know this before the end of the day, hope it can helps a bit. 
  
 Thanks. 
  
 Yale 


Thanks for your help, Yale 
 is it a bug?~ 
 if you fix it…when you can give me a fixed dll ?.. 


Carol, 
  
 Following post shows you how to do the oledb query in code snippet. 
 gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/6043/afv/topic/afpgj/1/Default.aspx#10062 
  
 I tried to make it work without a non-dbf extension file in oledb sql query, unfortunately failed. So I think if you want to do sql query on the data, probably you need to keep the dbf file extension unchanged. 
  
 Thanks. 
  
 Yale 


Thanks for your reply, Yale 

I'm sad to hear about this...:( 

I have to avoid my customer to open/see my document. 

As you said, I have to use .dbf file to ExecuteSql statement. 

Do you have any mehtod to protect .dbf file can't open by other users? 

for example, set user/password... 



i use follows code to create a new shp file, but i don't know if i can set password to protect my dbf file...or else? 

ShapeFileFeatureSource.CreateShapeFile(shapeFileType, newShapefilePath, DbfColumns)


Of course, it's better to solve original problem.



Carol,


Sorry for the delay.
 
Following post shows you how to make encryption on MapSuite3.0 with a sample included.
gis.thinkgeo.com/Support/Dis...fault.aspx
gis.thinkgeo.com/Support/Dis...fault.aspx
 
Any more questions just feel free to let me know.
 
Thanks.
 
Yale

Thanks for your help, Yale 
  
 I refer your code(gis.thinkgeo.com/Support/DiscussionForums/tabid/143/aff/21/aft/6043/afv/topic/afpgj/1/Default.aspx#10062 ), and OleDbConnection have to modify as follows: 
  
 OleDbConnection connection = new OleDbConnection("Provider=VFPOLEDB.1;Data Source=" + Path.GetDirectoryName(shapeFileName)+";Collating Sequence=MACHINE"); 
  
 it runs great! I can change my file name as I want. :) 
  
  
  
  


Carol, 
  
 That is awesome, I even did not think out of it! 
  
 Thanks for your sharing. 
  
 Yale 


Hello, 
 I’d like to know this problem will be solved in the next release version? 
 I hope the next release version can fix this problem…it is inconvenient.  :(

Carol, 
  
 Thanks for your post and suggestion.  
  
 We are planning to have a public release in May 1st, so we may do not have enough time to investigate on the side effect caused by this change.  So probably we have to make this change after the public release. Now, I will add this issue to our working item list. 
  
 Sorry for the inconvenience now. 
  
 Thanks. 
  
 Yale